Merge pull request #2756 from eclipse/jetty-9.4.x-2755-managed_selector_spin
Issue #2755 - Managed Selector 100% CPU Spin
This commit is contained in:
commit
34188fdaa8
|
@ -23,6 +23,7 @@ import java.io.IOException;
|
|||
import java.net.ConnectException;
|
||||
import java.net.SocketTimeoutException;
|
||||
import java.nio.channels.CancelledKeyException;
|
||||
import java.nio.channels.ClosedSelectorException;
|
||||
import java.nio.channels.SelectableChannel;
|
||||
import java.nio.channels.SelectionKey;
|
||||
import java.nio.channels.Selector;
|
||||
|
@ -101,7 +102,9 @@ public class ManagedSelector extends ContainerLifeCycle implements Dumpable
|
|||
_selectorManager.execute(_strategy::produce);
|
||||
|
||||
// Set started only if we really are started
|
||||
submit(s->_started.set(true));
|
||||
Start start = new Start();
|
||||
submit(start);
|
||||
start._started.await();
|
||||
}
|
||||
|
||||
public int size()
|
||||
|
@ -426,6 +429,9 @@ public class ManagedSelector extends ContainerLifeCycle implements Dumpable
|
|||
if (LOG.isDebugEnabled())
|
||||
LOG.debug("Selector {} woken up from select, {}/{}/{} selected", selector, selected, selector.selectedKeys().size(), selector.keys().size());
|
||||
|
||||
if (Thread.interrupted() && !isRunning())
|
||||
throw new ClosedSelectorException();
|
||||
|
||||
int updates;
|
||||
synchronized(ManagedSelector.this)
|
||||
{
|
||||
|
@ -536,6 +542,18 @@ public class ManagedSelector extends ContainerLifeCycle implements Dumpable
|
|||
public void update(Selector selector);
|
||||
}
|
||||
|
||||
private class Start implements SelectorUpdate
|
||||
{
|
||||
private final CountDownLatch _started = new CountDownLatch(1);
|
||||
|
||||
@Override
|
||||
public void update(Selector selector)
|
||||
{
|
||||
ManagedSelector.this._started.set(true);
|
||||
_started.countDown();
|
||||
}
|
||||
}
|
||||
|
||||
private static class DumpKeys implements SelectorUpdate
|
||||
{
|
||||
private CountDownLatch latch = new CountDownLatch(1);
|
||||
|
|
Loading…
Reference in New Issue