JNotify

File system events library for Java

相关站点

http://jnotify.sourceforge.net
http://jnotify.sourceforge.net/sample.html
http://jnotify.sourceforge.net/linux.html
https://sourceforge.net/projects/jnotify/files/

原理

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.

if you get an exception like :
net.contentobjects.jnotify.linux.JNotifyException_linux: Error watching /home/omry/file : No space left on device

it means the native inotify watch limit per process has been reached. the solution is to change the limit with a command like this (only root can do it):
echo 32000 > /proc/sys/fs/inotify/max_user_watches
which will set the maximum number of watches per process to 32000

Users of JNotify need to give up some of the functionality of the underlying system, for example, linux supports IN_CLOSE_NOWRITE event, and windows does not, it means JNotify will not support it. JNotify only support events on basic operations. it is, however, possible to use net.contentobjects.jnotify.linux.JNotify_linux class direclty, if you do not care about code portablity. this, however, means you will also no benefit from the clean API of JNotify and not from the recursive listening support.

代码

cvs -z3 -d:pserver:anonymous@a.cvs.sourceforge.net:/cvsroot/jnotify co -P jnotify
cvs -z3 -d:pserver:anonymous@a.cvs.sourceforge.net:/cvsroot/jnotify co -P jnotify_linux
cvs -z3 -d:pserver:anonymous@a.cvs.sourceforge.net:/cvsroot/jnotify co -P jnotify_macosx
cvs -z3 -d:pserver:anonymous@a.cvs.sourceforge.net:/cvsroot/jnotify co -P jnotify_releases
cvs -z3 -d:pserver:anonymous@a.cvs.sourceforge.net:/cvsroot/jnotify co -P jnotify_site
cvs -z3 -d:pserver:anonymous@a.cvs.sourceforge.net:/cvsroot/jnotify co -P jnotify_test
cvs -z3 -d:pserver:anonymous@a.cvs.sourceforge.net:/cvsroot/jnotify co -P jnotify_win32

©著作权归作者所有,转载或内容合作请联系作者
【社区内容提示】社区部分内容疑似由AI辅助生成,浏览时请结合常识与多方信息审慎甄别。
平台声明:文章内容(如有图片或视频亦包括在内)由作者上传并发布,文章内容仅代表作者本人观点,简书系信息发布平台,仅提供信息存储服务。

相关阅读更多精彩内容

  • rljs by sennchi Timeline of History Part One The Cognitiv...
    sennchi阅读 7,871评论 0 10
  • 标签(空格分隔): 数据结构与算法 定义: 它是一颗完全二叉树,它可以是空树中结点的值总是不大于或者不小于其孩子结...
    Sivin阅读 23,458评论 2 15
  • 社交软件可以让我们和很久不见的人维持联系,可以转发很多动态,可以记录生活。 但是,在某时某刻,我不想要让任何认识我...
    手鼓君阅读 312评论 0 0
  • 这是我在这里写的第一篇文章,想分享一些感受给大家,无所谓什么写作技巧,都是些真情实感罢了。 一字开头的年龄,失...
    宸Sea阅读 637评论 0 9
  • 每每说到寒风冷夜,总是想到一个孤寂的存在,王璇就是这样的。因为从小的家庭教育,让她失去了很多谈恋爱的机会,每...
    髓燕阅读 213评论 0 0

友情链接更多精彩内容