nio - Is Filewatcher considered non blocking IO in Java? -
this code snippet filewatcher java 7 nio library. non blocking code? threads waits signal filesystem.
for (;;) { // wait key signaled watchkey key; try { key = watcher.take(); } catch (interruptedexception x) { return; } }
filewatcher uses epoll
linux system call. it's multiplexing mechanism event based. windows there select
same thing, far less efficient , in bsd (which osx based on) there kqueue
.
in simple terms registers event handler in system waiting event occur. time progresses system takes @ queued event handlers , sees if there 1 ready proceed. if there event handler has it's event flag set true handle event. if there no events keep looping until finds event occurred.
in meantime code in main continues run, giving "non-blocking" functionality in promises.
this isn't new technology, although async has become quite popular rise of nodejs, swift , other non-blocking languages / frameworks same sort of thing how win32 api works - in short it's event based.
you can take @ link more in depth explanation.
Comments
Post a Comment