Bug 470727 - Thread Starvation of selector wakeups.

Added comment on running non-blocking code immediately.
This commit is contained in:
Simone Bordet 2015-07-08 12:48:53 +02:00
parent 4e3b400550
commit f62305b5a5
1 changed files with 11 additions and 8 deletions

View File

@ -100,22 +100,25 @@ public class SelectChannelEndPoint extends ChannelEndPoint implements ManagedSel
if (LOG.isDebugEnabled()) if (LOG.isDebugEnabled())
LOG.debug("onSelected {}->{} for {}", oldInterestOps, newInterestOps, this); LOG.debug("onSelected {}->{} for {}", oldInterestOps, newInterestOps, this);
boolean readable = (readyOps & SelectionKey.OP_READ) != 0; boolean readable = (readyOps & SelectionKey.OP_READ) != 0;
boolean writable = (readyOps & SelectionKey.OP_WRITE) != 0; boolean writable = (readyOps & SelectionKey.OP_WRITE) != 0;
// Call non blocking directly // Run non-blocking code immediately.
// This producer knows that this non-blocking code is special
// and that it must be run in this thread and not fed to the
// ExecutionStrategy, which could not have any thread to run these
// tasks (or it may starve forever just after having run them).
if (readable && getFillInterest().isCallbackNonBlocking()) if (readable && getFillInterest().isCallbackNonBlocking())
{ {
getFillInterest().fillable(); _runFillable.run();
readable=false; readable = false;
} }
if (writable && getWriteFlusher().isCallbackNonBlocking()) if (writable && getWriteFlusher().isCallbackNonBlocking())
{ {
getWriteFlusher().completeWrite(); _runCompleteWrite.run();
writable=false; writable = false;
} }
// return task to complete the job // return task to complete the job
return readable ? (writable ? _runFillableCompleteWrite : _runFillable) return readable ? (writable ? _runFillableCompleteWrite : _runFillable)
: (writable ? _runCompleteWrite : null); : (writable ? _runCompleteWrite : null);