mirror of
https://github.com/plan-player-analytics/Plan.git
synced 2025-01-08 17:37:34 +01:00
Improved concurrency access in some places
- FileWatcher should no longer throw ConcurrentModificationException - SessionCache should no longer throw ConcurrentModificationException
This commit is contained in:
parent
cd33f6bc32
commit
98462c3ac4
@ -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() {
|
||||
|
@ -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);
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user