Skip to content

Commit

Permalink
fix: the thread restarts with invalid path forever
Browse files Browse the repository at this point in the history
  • Loading branch information
Sharlottes committed Nov 7, 2023
1 parent 7c31a7d commit 2a53e58
Showing 1 changed file with 2 additions and 1 deletion.
3 changes: 2 additions & 1 deletion src/mlogwatcher/FileWatcher.java
Original file line number Diff line number Diff line change
Expand Up @@ -33,8 +33,9 @@ public FileWatcherThread(String targetFilePath) {
@Override
public void run() {
super.run();
Path targetFilePath = FileSystems.getDefault().getPath(this.targetFilePath).getParent();
try (final WatchService watchService = FileSystems.getDefault().newWatchService()) {
FileSystems.getDefault().getPath(targetFilePath).getParent().register(watchService, StandardWatchEventKinds.ENTRY_MODIFY);
targetFilePath.register(watchService, StandardWatchEventKinds.ENTRY_MODIFY);
while (true) {
final WatchKey watchKey = watchService.take();
for (WatchEvent<?> event : watchKey.pollEvents()) {
Expand Down

0 comments on commit 2a53e58

Please sign in to comment.