watch service does not detect more than one poll java

Solutions on MaxInterview for watch service does not detect more than one poll java by the best coders in the world

showing results for - "watch service does not detect more than one poll java"
Victoria
18 Mar 2020
1Path pathBattlesFolder = Paths.get("filepath");
2WatchService watchService = pathBattlesFolder.getFileSystem().newWatchService();
3pathBattlesFolder.register(watchService, StandardWatchEventKinds.ENTRY_MODIFY);
4WatchKey watchKey = null;
5while(true){
6
7  watchKey = watchService.poll();
8  if (watchKey != null){
9    if (watchKey.pollEvents().size() > 0){
10      //if it gets here then something has been changed
11    }
12    watchKey.reset();
13  }
14
15}
16
17**watchKey.reset() should fix the problem.