I was wondering what is the standard/best implementation of that in Java NIO. This is fundamental to implement something like heartbeats every N seconds, etc. Note: For obvious reasons (threads are evil and context switches are slow) everything must always happens inside the selector loop.
Note1: Answering Apache MINA does not count, unless you and the framework can demonstrate a clear scenario where this is done in a KISS (Keep It Simple Stupid) way.
Note2: Pipes require threads.
Not sure why you wouldn’t have a background thread for sending heartbeats or timing out connections. Heartbeats are not generally considered performance critical.
You can have the selector wait a specific amount of time and send heartbeats and check time outs at intervals.
Do you mean like