JNotify

File system events library for Java

相關(guān)站點(diǎn)

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

?著作權(quán)歸作者所有,轉(zhuǎn)載或內(nèi)容合作請(qǐng)聯(lián)系作者
【社區(qū)內(nèi)容提示】社區(qū)部分內(nèi)容疑似由AI輔助生成,瀏覽時(shí)請(qǐng)結(jié)合常識(shí)與多方信息審慎甄別。
平臺(tái)聲明:文章內(nèi)容(如有圖片或視頻亦包括在內(nèi))由作者上傳并發(fā)布,文章內(nèi)容僅代表作者本人觀點(diǎn),簡(jiǎn)書(shū)系信息發(fā)布平臺(tái),僅提供信息存儲(chǔ)服務(wù)。

相關(guān)閱讀更多精彩內(nèi)容

  • rljs by sennchi Timeline of History Part One The Cognitiv...
    sennchi閱讀 7,854評(píng)論 0 10
  • 標(biāo)簽(空格分隔): 數(shù)據(jù)結(jié)構(gòu)與算法 定義: 它是一顆完全二叉樹(shù),它可以是空樹(shù)中結(jié)點(diǎn)的值總是不大于或者不小于其孩子結(jié)...
    Sivin閱讀 23,443評(píng)論 2 15
  • 社交軟件可以讓我們和很久不見(jiàn)的人維持聯(lián)系,可以轉(zhuǎn)發(fā)很多動(dòng)態(tài),可以記錄生活。 但是,在某時(shí)某刻,我不想要讓任何認(rèn)識(shí)我...
    手鼓君閱讀 311評(píng)論 0 0
  • 這是我在這里寫(xiě)的第一篇文章,想分享一些感受給大家,無(wú)所謂什么寫(xiě)作技巧,都是些真情實(shí)感罷了。 一字開(kāi)頭的年齡,失...
    宸Sea閱讀 626評(píng)論 0 9
  • 每每說(shuō)到寒風(fēng)冷夜,總是想到一個(gè)孤寂的存在,王璇就是這樣的。因?yàn)閺男〉募彝ソ逃屗チ撕芏嗾剳賽?ài)的機(jī)會(huì),每...
    髓燕閱讀 212評(píng)論 0 0

友情鏈接更多精彩內(nèi)容