Domanda

I am being able to use Jnotify for listening events as file cration, modification etc. My concern is how Jnotify works. I mean what it uses get event. Is it safe to use in refrence of resource uses. I read in another SO question -- https://stackoverflow.com/questions/11100003/why-does-jnotify-consume-so-much-resources -- that it consume much resources.

Another way I can solve my problem is a while loop till a condition then program is shutdown.

Which will be better to use consumes less resources.

È stato utile?

Soluzione

linnotify talks to the kernel to get notified of filesystem changes. No polling, the kernel notifies on changes to the subscribed folders.

jnotify is a JNI wrapper around libjnotify.

Nonetheless, if you are using Java 7, all that is history, replaced by the new java file I/O (NIO.2) package.

Altri suggerimenti

From the site...

JNotify Linux support

JNotify Linux API is a thin wrapper around Linux INotify API. Since Linux INotify API does not support recursive listening on a directory, JNotify add this functionality by createing an INotify watch on every sub directory under the watched directory (transparently). this process takes a time which is linear to the number of directories in the tree being recursively watched, and require system resources, namely - INotify watches, which are limited, by default to 8192 watches per processes.

The limitations are documented. Also gives idea about implementation.

Your problem is related to File changed listener in Java , the highly voted answer there is DefaultFileMonitor, from Apache commons. I suggest you give it a try.

Autorizzato sotto: CC-BY-SA insieme a attribuzione
Non affiliato a StackOverflow
scroll top