How to check dynamically created file in Java?

I have an application where I need to check a file that can be created dynamically during my execution, I will refuse after some time MAX, when the file has not yet appeared. I wanted to know if there was a more efficient method in Java to check a file other than polling and then sleep every X seconds? If not for the most effective way to do this?

+3
source share
3 answers

You should currently poll the file system as you mentioned. Java 7 is supposed to have file system notifications , so at some point this should get easier.

+3
source

, , , Object.notify(). wait() notify/notifyAll() : http://java.sun.com/docs/books/tutorial/essential/concurrency/guardmeth.html

+1

JPoller .

Windows, , . . , -, JNA . , JSA-offsers, , FileMonitor ( ), .

If you look at an array of files or less, then, of course, polling is unlikely to be a performance problem, it’s just not a “good solution”, but not so bad as to justify the pain of an unclean java solution. Monitoring folders containing thousands of files, on the other hand, will benefit from direct notification from the OS.

0
source

Source: https://habr.com/ru/post/1743072/


All Articles