I implemented a directory watcher following the java tutorial: https://blogs.oracle.com/thejavatutorials/entry/watching_a_directory_for_changes
I have it on a separate thread that updates a JList. Everything seems to be working fine, what I wanted to know is: Do I need to do some type of cleanup somewhere and what would be the best way to do so if that's the case. Because that thread is basically waiting the whole time just in case something happens, after that it goes back to waiting for the next change.
Thanks for the help.
You should close the WatchService.
http://openjdk.java.net/projects/nio/javadoc/java/nio/file/WatchService.html#close()
Obviously, if you are going to watch the same path(s) for the duration of your program, you can just exit and rely on OS to clean up.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With