Merge pull request #4576 from eclipse/jetty-9.4.x-4575-stopping-reserved-threads
Fixes #4575 Stopping Reserved Thread
This commit is contained in:
commit
7320b1de94
|
@ -299,9 +299,6 @@ public class ReservedThreadExecutor extends AbstractLifeCycle implements TryExec
|
||||||
|
|
||||||
while (true)
|
while (true)
|
||||||
{
|
{
|
||||||
if (!isRunning())
|
|
||||||
return STOP;
|
|
||||||
|
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
Runnable task = _idleTime <= 0 ? _task.take() : _task.poll(_idleTime, _idleTimeUnit);
|
Runnable task = _idleTime <= 0 ? _task.take() : _task.poll(_idleTime, _idleTimeUnit);
|
||||||
|
@ -333,23 +330,26 @@ public class ReservedThreadExecutor extends AbstractLifeCycle implements TryExec
|
||||||
{
|
{
|
||||||
// test and increment size BEFORE decrementing pending,
|
// test and increment size BEFORE decrementing pending,
|
||||||
// so that we don't have a race starting new pending.
|
// so that we don't have a race starting new pending.
|
||||||
while (true)
|
int size = _size.get();
|
||||||
|
|
||||||
|
// Are we stopped?
|
||||||
|
if (size < 0)
|
||||||
|
return;
|
||||||
|
|
||||||
|
// Are we surplus to capacity?
|
||||||
|
if (size >= _capacity)
|
||||||
{
|
{
|
||||||
int size = _size.get();
|
if (LOG.isDebugEnabled())
|
||||||
if (size < 0)
|
LOG.debug("{} size {} > capacity", this, size, _capacity);
|
||||||
return;
|
if (_starting)
|
||||||
if (size >= _capacity)
|
_pending.decrementAndGet();
|
||||||
{
|
return;
|
||||||
if (LOG.isDebugEnabled())
|
|
||||||
LOG.debug("{} size {} > capacity", this, size, _capacity);
|
|
||||||
if (_starting)
|
|
||||||
_pending.decrementAndGet();
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
if (_size.compareAndSet(size, size + 1))
|
|
||||||
break;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// If we cannot update size then recalculate
|
||||||
|
if (!_size.compareAndSet(size, size + 1))
|
||||||
|
continue;
|
||||||
|
|
||||||
if (_starting)
|
if (_starting)
|
||||||
{
|
{
|
||||||
if (LOG.isDebugEnabled())
|
if (LOG.isDebugEnabled())
|
||||||
|
@ -362,7 +362,8 @@ public class ReservedThreadExecutor extends AbstractLifeCycle implements TryExec
|
||||||
// that only effects the decision to keep other threads reserved.
|
// that only effects the decision to keep other threads reserved.
|
||||||
_stack.offerFirst(this);
|
_stack.offerFirst(this);
|
||||||
|
|
||||||
// Wait for a task
|
// Once added to the stack, we must always wait for a job on the _task Queue
|
||||||
|
// and never return early, else we may leave a thread blocked offering a _task.
|
||||||
Runnable task = reservedWait();
|
Runnable task = reservedWait();
|
||||||
|
|
||||||
if (task == STOP)
|
if (task == STOP)
|
||||||
|
|
Loading…
Reference in New Issue