How does Jnotify works

岁酱吖の 提交于 2019-12-12 18:34:09

问题


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.


回答1:


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.




回答2:


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.



来源:https://stackoverflow.com/questions/11632277/how-does-jnotify-works

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!