I am making a desktop application that monitors a directory that contains dynamic sub-directories and files. There are a lot of files(logs) being created in these sub-directories. I want to make an application that watches these files being created (around 50 files created within 5 mins) notify.
I went through the WatchDir provided by java.nio
, but as we need to register a watchkey
for each directory, I fear I might run into some concurrency issues later on.
I tried searching for alternatives and I found monitor
by Apache Commons, but it takes up a lot of CPU as per this answer. In my case I want to monitor large amount of files but they are also not continuous. I want to watch files only for a few hours in a day and during this time there will be a lot of files generated. What would be the best option here?