Issue #2755 - ManagedSelector 100% CPU spin.

Avoid race between doStart() and doStop() by waiting in doStart()
for _started=true.

Signed-off-by: Simone Bordet <simone.bordet@gmail.com>
This commit is contained in:
Simone Bordet 2018-08-01 17:25:46 +02:00
parent a090741a60
commit 0a336230ef
1 changed files with 15 additions and 1 deletions

View File

@ -102,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()
@ -540,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);