Pathwatcher Concurrent modification #4174 (#4175)

There is a race between the doStop clearing the key map and the watching thread
checking isRunning before iterating over the key map.

While more sophisticated approaches could be used, I think that is best to defer
until this class is reworked entirely.  For now just using a ConcurrentHashMap will
avoid the exception and the closing of the pathwatcher will prevent watching forever.

Signed-off-by: Greg Wilkins <gregw@webtide.com>
This commit is contained in:
Greg Wilkins 2019-10-09 13:58:16 +11:00 committed by GitHub
parent 31a0180133
commit 0bd71a4359
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
1 changed files with 2 additions and 1 deletions

View File

@ -43,6 +43,7 @@ import java.util.List;
import java.util.Locale;
import java.util.Map;
import java.util.Scanner;
import java.util.concurrent.ConcurrentHashMap;
import java.util.concurrent.CopyOnWriteArrayList;
import java.util.concurrent.TimeUnit;
import java.util.function.Predicate;
@ -742,7 +743,7 @@ public class PathWatcher extends AbstractLifeCycle implements Runnable
private boolean nativeWatchService;
private final List<Config> configs = new ArrayList<>();
private final Map<WatchKey, Config> keys = new HashMap<>();
private final Map<WatchKey, Config> keys = new ConcurrentHashMap<>();
private final List<EventListener> listeners = new CopyOnWriteArrayList<>(); //a listener may modify the listener list directly or by stopping the PathWatcher
private final Map<Path, PathWatchEvent> pending = new LinkedHashMap<>(32, (float)0.75, false);