Improved concurrency access in some places

- FileWatcher should no longer throw ConcurrentModificationException
- SessionCache should no longer throw ConcurrentModificationException
This commit is contained in:
Rsl1122 2019-08-21 09:58:05 +03:00
parent cd33f6bc32
commit 98462c3ac4
2 changed files with 6 additions and 6 deletions

View File

@ -22,10 +22,10 @@ import com.google.common.collect.ImmutableMap;
import javax.inject.Inject;
import javax.inject.Singleton;
import java.util.HashMap;
import java.util.Map;
import java.util.Optional;
import java.util.UUID;
import java.util.concurrent.ConcurrentHashMap;
/**
* This class is used to store active sessions of players in memory.
@ -35,7 +35,7 @@ import java.util.UUID;
@Singleton
public class SessionCache {
private static final Map<UUID, Session> ACTIVE_SESSIONS = new HashMap<>();
private static final Map<UUID, Session> ACTIVE_SESSIONS = new ConcurrentHashMap<>();
@Inject
public SessionCache() {

View File

@ -23,8 +23,9 @@ import com.djrapitops.plugin.utilities.Verify;
import java.io.File;
import java.io.IOException;
import java.nio.file.*;
import java.util.HashSet;
import java.util.Collections;
import java.util.Set;
import java.util.concurrent.ConcurrentHashMap;
import static java.nio.file.StandardWatchEventKinds.ENTRY_MODIFY;
@ -55,8 +56,7 @@ public class FileWatcher extends Thread {
) {
this.errorHandler = errorHandler;
this.running = false;
this.watchedFiles = new HashSet<>();
this.watchedFiles = Collections.newSetFromMap(new ConcurrentHashMap<>());
Verify.isTrue(watchedPath.toFile().isDirectory(), () -> new IllegalArgumentException("Given File " + watchedPath.toString() + " was not a folder."));
@ -116,7 +116,7 @@ public class FileWatcher extends Thread {
}
private void actOnModification(Path modifiedFile) {
for (WatchedFile watchedFile : new HashSet<>(watchedFiles)) {
for (WatchedFile watchedFile : watchedFiles) {
watchedFile.modified(modifiedFile);
}
}