Fixes #1805 - ReservedThreadExecutor should start ReservedThreads lazily.
Removed doStart() that was eagerly starting ReservedThreads. Other small code cleanups.
This commit is contained in:
parent
5d8c605d96
commit
c1a4153861
|
@ -107,20 +107,6 @@ public class ReservedThreadExecutor extends AbstractLifeCycle implements Executo
|
|||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void doStart() throws Exception
|
||||
{
|
||||
try (Locker.Lock lock = _locker.lock())
|
||||
{
|
||||
_head = _size = _pending = 0;
|
||||
while (_pending<_queue.length)
|
||||
{
|
||||
_executor.execute(new ReservedThread());
|
||||
_pending++;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void doStop() throws Exception
|
||||
{
|
||||
|
@ -188,6 +174,15 @@ public class ReservedThreadExecutor extends AbstractLifeCycle implements Executo
|
|||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString()
|
||||
{
|
||||
try (Locker.Lock lock = _locker.lock())
|
||||
{
|
||||
return String.format("%s{s=%d,p=%d}",super.toString(),_size,_pending);
|
||||
}
|
||||
}
|
||||
|
||||
private class ReservedThread implements Runnable
|
||||
{
|
||||
private Condition _wakeup = null;
|
||||
|
@ -204,7 +199,6 @@ public class ReservedThreadExecutor extends AbstractLifeCycle implements Executo
|
|||
while (true)
|
||||
{
|
||||
Runnable task = null;
|
||||
|
||||
try (Locker.Lock lock = _locker.lock())
|
||||
{
|
||||
// if this is our first loop, decrement pending count
|
||||
|
@ -221,12 +215,16 @@ public class ReservedThreadExecutor extends AbstractLifeCycle implements Executo
|
|||
// Insert ourselves in the queue
|
||||
_queue[(_head+_size++)%_queue.length] = this;
|
||||
|
||||
// Wait for a task, ignoring spurious interrupts
|
||||
do
|
||||
// Wait for a task, ignoring spurious wakeups
|
||||
while (isRunning() && task==null)
|
||||
{
|
||||
try
|
||||
{
|
||||
if (LOG.isDebugEnabled())
|
||||
LOG.debug("{} waiting", this);
|
||||
reservedWait();
|
||||
if (LOG.isDebugEnabled())
|
||||
LOG.debug("{} woken up", this);
|
||||
task = _task;
|
||||
_task = null;
|
||||
}
|
||||
|
@ -235,7 +233,6 @@ public class ReservedThreadExecutor extends AbstractLifeCycle implements Executo
|
|||
LOG.ignore(e);
|
||||
}
|
||||
}
|
||||
while (isRunning() && task==null);
|
||||
}
|
||||
|
||||
// Run any task
|
||||
|
@ -245,22 +242,12 @@ public class ReservedThreadExecutor extends AbstractLifeCycle implements Executo
|
|||
{
|
||||
task.run();
|
||||
}
|
||||
catch (Exception e)
|
||||
catch (Throwable e)
|
||||
{
|
||||
LOG.warn(e);
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString()
|
||||
{
|
||||
try (Locker.Lock lock = _locker.lock())
|
||||
{
|
||||
return String.format("%s{s=%d,p=%d}",super.toString(),_size,_pending);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue