挖了个天坑。

This commit is contained in:
坏黑
2018-08-09 11:58:31 +08:00
parent 88cc9cc7bf
commit 600ac49622
7 changed files with 49 additions and 36 deletions

View File

@@ -19,9 +19,7 @@ import java.util.function.Consumer;
*/
public class TConfigWatcher {
private final ScheduledExecutorService service = Executors.newScheduledThreadPool(1,
new BasicThreadFactory.Builder().namingPattern("TConfigWatcherService-%d").build());
private final ScheduledExecutorService service = Executors.newScheduledThreadPool(1, new BasicThreadFactory.Builder().namingPattern("TConfigWatcherService-%d").build());
private final Map<WatchService, Triple<File, Object, Consumer<Object>>> map = new HashMap<>();
public TConfigWatcher() {
@@ -42,6 +40,10 @@ public class TConfigWatcher {
}, 1000, 100, TimeUnit.MILLISECONDS);
}
public void addSimpleListener(File file, Runnable runnable) {
addListener(file, null, obj -> runnable.run());
}
public void addOnListen(File file, Object obj, Consumer<Object> consumer) {
try {
WatchService service = FileSystems.getDefault().newWatchService();
@@ -82,5 +84,4 @@ public class TConfigWatcher {
}
});
}
}