I have defined a class(callable) named “folderwatcher” that is monitoring a specific folder for any changes. The main code is in an infinite loop similar to: Monitor a Directory for Changes using Java. I want the method/class that calls this “folderwatcher” to listen for any events discovered by the “folderwatcher” and does some operations based on the event. Does anyone know how I can do this? Do I need an event handler? any examples?
thanks
I have defined a class(callable) named folderwatcher that is monitoring a specific folder for
Share
First of all, it is wrong to use an infinite loop approach. if you are really using
Callablethen you are already using anExecutorService. What you should use is aScheduledExecutorServiceand schedule your code as a repeated task.As far as an event handler, this is not hard to accomplish, for example: