@ManagedObject(value="eat what you kill execution strategy") public class EatWhatYouKill extends ContainerLifeCycle implements ExecutionStrategy, java.lang.Runnable
A strategy where the thread that produces will run the resulting task if it is possible to do so without thread starvation.
This strategy preemptively dispatches a thread as a pending producer, so that when a thread produces a task it can immediately run the task and let the pending producer thread take over producing. If necessary another thread will be dispatched to replace the pending producing thread. When operating in this pattern, the sub-strategy is called Execute Produce Consume (EPC)
However, if the task produced uses the Invocable
API to indicate that
it will not block, then the strategy will run it directly, regardless of the
presence of a pending producing thread and then resume producing after the
task has completed. This sub-strategy is also used if the strategy has been
configured with a maximum of 0 pending threads and the thread currently producing
does not use the Invocable
API to indicate that it will not block.
When operating in this pattern, the sub-strategy is called
ProduceConsume (PC).
If there is no pending producer thread available and if the task has not indicated it is non-blocking, then this strategy will dispatch the execution of the task and immediately continue producing. When operating in this pattern, the sub-strategy is called ProduceExecuteConsume (PEC).
Modifier and Type | Class and Description |
---|---|
private static class |
EatWhatYouKill.Mode |
private static class |
EatWhatYouKill.State |
AbstractLifeCycle.AbstractLifeCycleListener
ExecutionStrategy.Producer
Container.InheritedListener, Container.Listener
LifeCycle.Listener
Modifier and Type | Field and Description |
---|---|
private java.util.concurrent.atomic.LongAdder |
_epcMode |
private java.util.concurrent.Executor |
_executor |
private java.util.concurrent.atomic.LongAdder |
_pcMode |
private java.util.concurrent.atomic.LongAdder |
_pecMode |
private boolean |
_pending |
private java.util.concurrent.atomic.LongAdder |
_picMode |
private ExecutionStrategy.Producer |
_producer |
private EatWhatYouKill.State |
_state |
private TryExecutor |
_tryExecutor |
private static Logger |
LOG |
FAILED, RUNNING, STARTED, STARTING, STOP_ON_FAILURE, STOPPED, STOPPING
Constructor and Description |
---|
EatWhatYouKill(ExecutionStrategy.Producer producer,
java.util.concurrent.Executor executor) |
Modifier and Type | Method and Description |
---|---|
void |
dispatch()
Initiates (or resumes) the task production and consumption.
|
boolean |
doProduce(boolean non_blocking) |
private void |
execute(java.lang.Runnable task) |
long |
getEPCTasksConsumed() |
long |
getPCTasksConsumed() |
long |
getPECTasksExecuted() |
long |
getPICTasksExecuted() |
private void |
getState(java.lang.StringBuilder builder) |
private void |
getString(java.lang.StringBuilder builder) |
boolean |
isIdle() |
void |
produce()
Initiates (or resumes) the task production and consumption.
|
private java.lang.Runnable |
produceTask() |
void |
reset() |
void |
run() |
java.lang.String |
toString() |
java.lang.String |
toStringLocked() |
private void |
tryProduce(boolean wasPending) |
addBean, addBean, addBean, addEventListener, addManaged, contains, destroy, doStart, doStop, dump, dump, dump, dump, dump, dumpBeans, dumpObject, dumpStdErr, dumpThis, getBean, getBeans, getBeans, getContainedBeans, getContainedBeans, isManaged, manage, removeBean, removeBeans, removeEventListener, setBeans, setStopTimeout, start, stop, unmanage, updateBean, updateBean, updateBeans
addLifeCycleListener, getState, getState, getStopTimeout, isFailed, isRunning, isStarted, isStarting, isStopped, isStopping, removeLifeCycleListener, start, stop
private static final Logger LOG
private final java.util.concurrent.atomic.LongAdder _pcMode
private final java.util.concurrent.atomic.LongAdder _picMode
private final java.util.concurrent.atomic.LongAdder _pecMode
private final java.util.concurrent.atomic.LongAdder _epcMode
private final ExecutionStrategy.Producer _producer
private final java.util.concurrent.Executor _executor
private final TryExecutor _tryExecutor
private EatWhatYouKill.State _state
private boolean _pending
public EatWhatYouKill(ExecutionStrategy.Producer producer, java.util.concurrent.Executor executor)
public void dispatch()
ExecutionStrategy
Initiates (or resumes) the task production and consumption.
This method guarantees that the task is never run by the thread that called this method.
TODO review the need for this (only used by HTTP2 push)dispatch
in interface ExecutionStrategy
ExecutionStrategy.produce()
public void run()
run
in interface java.lang.Runnable
public void produce()
ExecutionStrategy
Initiates (or resumes) the task production and consumption.
The produced task may be run by the same thread that called this method.
produce
in interface ExecutionStrategy
ExecutionStrategy.dispatch()
private void tryProduce(boolean wasPending)
public boolean doProduce(boolean non_blocking)
private java.lang.Runnable produceTask()
private void execute(java.lang.Runnable task)
@ManagedAttribute(value="number of tasks consumed with PC mode", readonly=true) public long getPCTasksConsumed()
@ManagedAttribute(value="number of tasks executed with PIC mode", readonly=true) public long getPICTasksExecuted()
@ManagedAttribute(value="number of tasks executed with PEC mode", readonly=true) public long getPECTasksExecuted()
@ManagedAttribute(value="number of tasks consumed with EPC mode", readonly=true) public long getEPCTasksConsumed()
@ManagedAttribute(value="whether this execution strategy is idle", readonly=true) public boolean isIdle()
@ManagedOperation(value="resets the task counts", impact="ACTION") public void reset()
public java.lang.String toString()
toString
in class java.lang.Object
public java.lang.String toStringLocked()
private void getString(java.lang.StringBuilder builder)
private void getState(java.lang.StringBuilder builder)