According to Javadok,
It returns only after at least one channel is selected, this method of triggering the selector is called, the current thread is interrupted or the specified waiting period expires, whichever comes first.
But sometimes he returns without any of these four cases:
- at least one channel is selected: it returns 0
- Awakening method called:
wakeup
not called - the current thread is interrupted: Thread.interrupted () returns false
- set timeout expires: not expired according to logs
UPDATED 2016-03-15
In my source on line 392 and line 402 I added some logs: https://github.com/xqbase/tuna/blob/debug/core/src/main/java/com/xqbase/tuna/ConnectorImpl.java
public boolean doEvents(long timeout) { Log.v("Before Select: " + timeout); int keySize; try { keySize = timeout == 0 ? selector.selectNow() : timeout < 0 ? selector.select() : selector.select(timeout); } catch (IOException e) { throw new RuntimeException(e); } Set<SelectionKey> selectedKeys = selector.selectedKeys(); if (keySize == 0) { Log.v("After Select(0): selectedKeys=" + selectedKeys.size() + ", " + "interrupt=" + Thread.interrupted()); invokeQueue(); return false; } for (SelectionKey key : selectedKeys) { ...
Here is the log:
... 2016-03-15 23:07:49.695 com.xqbase.tuna.ConnectorImpl doEvents FINE: Before Select: 8120 2016-03-15 23:07:49.696 com.xqbase.tuna.ConnectorImpl doEvents FINE: After Select(0): selectedKeys=0, interrupt=false 2016-03-15 23:07:49.696 com.xqbase.tuna.ConnectorImpl doEvents FINE: Before Select: 8119 2016-03-15 23:07:49.696 com.xqbase.tuna.ConnectorImpl doEvents FINE: After Select(0): selectedKeys=0, interrupt=false 2016-03-15 23:07:49.700 com.xqbase.tuna.ConnectorImpl doEvents FINE: Before Select: 8115 2016-03-15 23:07:49.701 com.xqbase.tuna.ConnectorImpl doEvents FINE: After Select(0): selectedKeys=0, interrupt=false 2016-03-15 23:07:49.701 com.xqbase.tuna.ConnectorImpl doEvents FINE: Before Select: 8114 2016-03-15 23:07:49.702 com.xqbase.tuna.ConnectorImpl doEvents FINE: After Select(0): selectedKeys=0, interrupt=false ...
This is very strange: no keys selected, without interruption, without a timeout and without waking up, but he returned.
Is there a bug in Java? My Java version is 1.8.0_51-b16 (64-bit server VM) and runs on linux CentOS 6.5 x64.
source share