I'm trying to run a NIO Server in it's own Thread.
In my run function I defined:
while(running)
{
System.out.println("Server running!");
try
{
this.selector.select();
}
catch (IOException e)
{
e.printStackTrace();
}
}
The run loops only runs one time and then it's stuck. Without the whole try block it works.
It the selector.select() blocking somehow?
The documentation says,
This method performs a blocking selection operation. It returns only after at least one channel is selected, this selector's wakeup method is invoked, or the current thread is interrupted, whichever comes first.
So it should block until a channel is selected.
For non-blocking select/busy loop, try selectNow method.