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:[email protected]:/cvsroot/jnotify co -P jnotify
cvs -z3 -d:pserver:[email protected]:/cvsroot/jnotify co -P jnotify_linux
cvs -z3 -d:pserver:[email protected]:/cvsroot/jnotify co -P jnotify_macosx
cvs -z3 -d:pserver:[email protected]:/cvsroot/jnotify co -P jnotify_releases
cvs -z3 -d:pserver:[email protected]:/cvsroot/jnotify co -P jnotify_site
cvs -z3 -d:pserver:[email protected]:/cvsroot/jnotify co -P jnotify_test
cvs -z3 -d:pserver:[email protected]:/cvsroot/jnotify co -P jnotify_win32

你可能感兴趣的:(JNotify)