name.pachler.nio.file.impl
Class LinuxPathWatchService

java.lang.Object
  extended by name.pachler.nio.file.WatchService
      extended by name.pachler.nio.file.impl.PathWatchService
          extended by name.pachler.nio.file.impl.LinuxPathWatchService
All Implemented Interfaces:
java.io.Closeable

public class LinuxPathWatchService
extends PathWatchService

This Linux implementation of the WatchService interface works without the use of threads or asynchronous I/O, using Linux' inotify file system event facitily.

The implementation hinges around select() to wait for events on the inotify file descriptor that each LinuxPathWatchService. Each time a WatchKey is registered (through Path.register(), which eventually calls register() on the LinuxPathWatchService), inotify_add_watch() is called on the service's inotify file descriptor.
To wait for events, the take() and poll() methods use select() to wait for the inotify FD to become readable.
However, a lot of things can happen while a thread is waiting inside poll() or take() with select():