java - WatchService: missed and unhandled events -


i'm having issue watchservice. here snippet of code:

public void watch(){   //define folder root   path mydir = paths.get(rootdir+"inputfiles/"+dirname+"/request");          try {     watchservice watcher = mydir.getfilesystem().newwatchservice();     mydir.register(watcher, standardwatcheventkinds.entry_create);       watchkey watckkey = watcher.take();      list<watchevent<?>> events = watckkey.pollevents();     (watchevent event : events) {       //stuff     }   }catch(exception e){}    watckkey.reset();  } 

*first of all, know watch() called inside infinite loop.

the problem when creating multiple files @ time, events missing. example, if copy-paste 3 files ".../request" folder, 1 gets caught, others remain if nothing happened, neither overflow event triggered. in different computer , os, reaches 2 files, if 1 tries 3 or more, rest still untouched.

i found workaround though, don't think it's best practice. flow:

the process starts , stops @

watchkey watckkey = watcher.take(); 

as expected, (as per processing events). then, drop 3 files in "request" folder, thus, process resumes at

list<watchevent<?>> events = watckkey.pollevents(); 

the issue here. seems thread goes fast through line 2 created events stay behind , lost, 1 taken. workaround add line right above one, this:

thread.sleep(1000); list<watchevent<?>> events = watckkey.pollevents(); 

this seems solution, @ least 3 , several more simultaneous files, it's not scalable @ all. in conclusion, know if there better solution issue. fyi, i'm running win 7 64

thanks lot in advance!


Comments

Popular posts from this blog

c++ - No viable overloaded operator for references a map -

java - Custom OutputStreamAppender not run: LOGBACK: No context given for <MYAPPENDER> -

java - Cannot secure connection using TLS -