Issue #547 EWYK leaves low resource mode

Merged code cleanups
This commit is contained in:
Greg Wilkins 2016-05-05 11:35:32 +10:00
parent 6591137ba0
commit c77df55bb6
1 changed files with 29 additions and 12 deletions

View File

@ -19,11 +19,12 @@
package org.eclipse.jetty.util.thread.strategy;
import java.util.concurrent.Executor;
import java.util.concurrent.RejectedExecutionException;
import org.eclipse.jetty.util.log.Log;
import org.eclipse.jetty.util.log.Logger;
import org.eclipse.jetty.util.thread.ExecutionStrategy;
import org.eclipse.jetty.util.thread.Locker;
import org.eclipse.jetty.util.thread.Locker.Lock;
/**
* <p>A strategy where the caller thread iterates over task production, submitting each
@ -33,6 +34,7 @@ public class ProduceExecuteConsume extends ExecutingExecutionStrategy implements
{
private static final Logger LOG = Log.getLogger(ProduceExecuteConsume.class);
private final Locker _locker = new Locker();
private final Producer _producer;
private State _state = State.IDLE;
@ -45,14 +47,22 @@ public class ProduceExecuteConsume extends ExecutingExecutionStrategy implements
@Override
public void execute()
{
synchronized (this)
try (Lock locked = _locker.lock())
{
_state = _state == State.IDLE ? State.PRODUCE : State.EXECUTE;
if (_state == State.EXECUTE)
return;
switch(_state)
{
case IDLE:
_state=State.PRODUCE;
break;
case PRODUCE:
case EXECUTE:
_state=State.EXECUTE;
return;
}
}
// Iterate until we are complete.
// Produce until we no task is found.
while (true)
{
// Produce a task.
@ -62,18 +72,25 @@ public class ProduceExecuteConsume extends ExecutingExecutionStrategy implements
if (task == null)
{
synchronized (this)
try (Lock locked = _locker.lock())
{
_state = _state == State.PRODUCE ? State.IDLE : State.PRODUCE;
if (_state == State.PRODUCE)
continue;
return;
switch(_state)
{
case IDLE:
throw new IllegalStateException();
case PRODUCE:
_state=State.IDLE;
return;
case EXECUTE:
_state=State.PRODUCE;
continue;
}
}
}
// Execute the task.
execute(task);
}
}
}
@Override