Small optimization when starting reserved threads.

Signed-off-by: Simone Bordet <simone.bordet@gmail.com>
This commit is contained in:
Simone Bordet 2017-11-28 22:02:52 +01:00
parent 00d977d5d5
commit 31e5531966
1 changed files with 3 additions and 2 deletions

View File

@ -231,14 +231,15 @@ public class ReservedThreadExecutor extends AbstractLifeCycle implements Executo
{ {
while (true) while (true)
{ {
// Not atomic, but there is a re-check in ReservedThread.run().
int pending = _pending.get(); int pending = _pending.get();
if (pending >= _capacity) int size = _size.get();
if (pending + size >= _capacity)
return; return;
if (_pending.compareAndSet(pending, pending + 1)) if (_pending.compareAndSet(pending, pending + 1))
{ {
if (LOG.isDebugEnabled()) if (LOG.isDebugEnabled())
LOG.debug("{} startReservedThread p={}", this, pending + 1); LOG.debug("{} startReservedThread p={}", this, pending + 1);
_executor.execute(new ReservedThread()); _executor.execute(new ReservedThread());
return; return;
} }