mirror of
https://github.com/plan-player-analytics/Plan.git
synced 2025-01-09 18:07:39 +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.Inject;
|
||||||
import javax.inject.Singleton;
|
import javax.inject.Singleton;
|
||||||
import java.util.HashMap;
|
|
||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
import java.util.Optional;
|
import java.util.Optional;
|
||||||
import java.util.UUID;
|
import java.util.UUID;
|
||||||
|
import java.util.concurrent.ConcurrentHashMap;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* This class is used to store active sessions of players in memory.
|
* This class is used to store active sessions of players in memory.
|
||||||
@ -35,7 +35,7 @@ import java.util.UUID;
|
|||||||
@Singleton
|
@Singleton
|
||||||
public class SessionCache {
|
public class SessionCache {
|
||||||
|
|
||||||
private static final Map<UUID, Session> ACTIVE_SESSIONS = new HashMap<>();
|
private static final Map<UUID, Session> ACTIVE_SESSIONS = new ConcurrentHashMap<>();
|
||||||
|
|
||||||
@Inject
|
@Inject
|
||||||
public SessionCache() {
|
public SessionCache() {
|
||||||
|
@ -23,8 +23,9 @@ import com.djrapitops.plugin.utilities.Verify;
|
|||||||
import java.io.File;
|
import java.io.File;
|
||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
import java.nio.file.*;
|
import java.nio.file.*;
|
||||||
import java.util.HashSet;
|
import java.util.Collections;
|
||||||
import java.util.Set;
|
import java.util.Set;
|
||||||
|
import java.util.concurrent.ConcurrentHashMap;
|
||||||
|
|
||||||
import static java.nio.file.StandardWatchEventKinds.ENTRY_MODIFY;
|
import static java.nio.file.StandardWatchEventKinds.ENTRY_MODIFY;
|
||||||
|
|
||||||
@ -55,8 +56,7 @@ public class FileWatcher extends Thread {
|
|||||||
) {
|
) {
|
||||||
this.errorHandler = errorHandler;
|
this.errorHandler = errorHandler;
|
||||||
this.running = false;
|
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."));
|
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) {
|
private void actOnModification(Path modifiedFile) {
|
||||||
for (WatchedFile watchedFile : new HashSet<>(watchedFiles)) {
|
for (WatchedFile watchedFile : watchedFiles) {
|
||||||
watchedFile.modified(modifiedFile);
|
watchedFile.modified(modifiedFile);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user