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.ConnectException;
|
||||||
import java.net.SocketTimeoutException;
|
import java.net.SocketTimeoutException;
|
||||||
import java.nio.channels.CancelledKeyException;
|
import java.nio.channels.CancelledKeyException;
|
||||||
|
import java.nio.channels.ClosedSelectorException;
|
||||||
import java.nio.channels.SelectableChannel;
|
import java.nio.channels.SelectableChannel;
|
||||||
import java.nio.channels.SelectionKey;
|
import java.nio.channels.SelectionKey;
|
||||||
import java.nio.channels.Selector;
|
import java.nio.channels.Selector;
|
||||||
|
@ -101,7 +102,9 @@ public class ManagedSelector extends ContainerLifeCycle implements Dumpable
|
||||||
_selectorManager.execute(_strategy::produce);
|
_selectorManager.execute(_strategy::produce);
|
||||||
|
|
||||||
// Set started only if we really are started
|
// 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()
|
public int size()
|
||||||
|
@ -426,6 +429,9 @@ public class ManagedSelector extends ContainerLifeCycle implements Dumpable
|
||||||
if (LOG.isDebugEnabled())
|
if (LOG.isDebugEnabled())
|
||||||
LOG.debug("Selector {} woken up from select, {}/{}/{} selected", selector, selected, selector.selectedKeys().size(), selector.keys().size());
|
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;
|
int updates;
|
||||||
synchronized(ManagedSelector.this)
|
synchronized(ManagedSelector.this)
|
||||||
{
|
{
|
||||||
|
@ -536,6 +542,18 @@ public class ManagedSelector extends ContainerLifeCycle implements Dumpable
|
||||||
public void update(Selector selector);
|
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 static class DumpKeys implements SelectorUpdate
|
||||||
{
|
{
|
||||||
private CountDownLatch latch = new CountDownLatch(1);
|
private CountDownLatch latch = new CountDownLatch(1);
|
||||||
|
|
Loading…
Reference in New Issue