Synchronize on the class instead of the instance

I didn't realize it before, but it looks like there is at least one instance of YamlRegionFile per world, so synchronizing on the instance wouldn't necessarily help.
This commit is contained in:
TomyLobo 2023-06-12 03:16:14 +02:00
parent 7ba0fd3f53
commit 5763f53415

View File

@ -192,9 +192,10 @@ public Set<ProtectedRegion> loadAll(FlagRegistry flagRegistry) throws StorageExc
} }
@Override @Override
public synchronized void saveAll(Set<ProtectedRegion> regions) throws StorageException { public void saveAll(Set<ProtectedRegion> regions) throws StorageException {
checkNotNull(regions); checkNotNull(regions);
synchronized (YamlRegionFile.class) {
File tempFile = new File(file.getParentFile(), file.getName() + ".tmp"); File tempFile = new File(file.getParentFile(), file.getName() + ".tmp");
YAMLProcessor config = createYamlProcessor(tempFile); YAMLProcessor config = createYamlProcessor(tempFile);
@ -254,6 +255,7 @@ public synchronized void saveAll(Set<ProtectedRegion> regions) throws StorageExc
throw new StorageException("Failed to rename temporary regions file to " + file.getAbsolutePath()); throw new StorageException("Failed to rename temporary regions file to " + file.getAbsolutePath());
} }
} }
}
@Override @Override
public void saveChanges(RegionDifference difference) throws DifferenceSaveException { public void saveChanges(RegionDifference difference) throws DifferenceSaveException {