Adding return statement to watchable in Java -


how add return statement watchable method in java , still working properly. want searching files, ok have that. want return, when add return statement goes down function stops , watchable stops .. ideas ?

for (;;) {     watchkey key = watcher.take();     (watchevent<?> event: key.pollevents()) {         if (event.kind() == standardwatcheventkind.entry_create) {             system.out.println(event.context().tostring());     } } 

here loop searches, how return , still working?

as @dlev says, if want application process watch events @ same time doing other things, way in separate thread.

this leaves problem of "returning" information. (i presume printing information standard output not use you.)

as observed, can't use return because terminate loop.

the basic answer need put information somewhere rest of application can access. example:

  • you create queue object (e.g. concurrentlinkedqueue), have watcher enqueue data, , have other thread dequeue , process it.

  • you have watcher process event payload , put results shared data structure.

however, without more information, difficult decide approach best you.


Comments

Popular posts from this blog

c# - how to write client side events functions for the combobox items -

exception - Python, pyPdf OCR error: pyPdf.utils.PdfReadError: EOF marker not found -