This NIO example uses the new(ish) Selector.select(Consumer<?>)
api
which seems to solve a lot of the spurious wakeup problems in previous examples.
The example also demonstrates performing channel read/write functions asynchronously via SelectionKey interestOps() and attach() manipulation.