Class EatWhatYouKill
- java.lang.Object
-
- org.eclipse.jetty.util.component.AbstractLifeCycle
-
- org.eclipse.jetty.util.component.ContainerLifeCycle
-
- org.eclipse.jetty.util.thread.strategy.EatWhatYouKill
-
- All Implemented Interfaces:
java.lang.Runnable,Container,Destroyable,Dumpable,Dumpable.DumpableContainer,LifeCycle,ExecutionStrategy
@ManagedObject("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 production. When operating in this way, the sub-strategy is called Execute Produce Consume (EPC).
However, if the task produced uses the
InvocableAPI to indicate that it will not block, then the strategy will run it directly, regardless of the presence of a pending producer thread and then resume production after the task has completed. 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 production. When operating in this pattern, the sub-strategy is called ProduceExecuteConsume (PEC).
The EatWhatYouKill strategy is named after a hunting proverb, in the sense that one should kill(produce) only to eat(consume).
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description private static classEatWhatYouKill.Modeprivate static classEatWhatYouKill.State-
Nested classes/interfaces inherited from class org.eclipse.jetty.util.component.AbstractLifeCycle
AbstractLifeCycle.AbstractLifeCycleListener
-
Nested classes/interfaces inherited from interface org.eclipse.jetty.util.component.Container
Container.InheritedListener, Container.Listener
-
Nested classes/interfaces inherited from interface org.eclipse.jetty.util.component.Dumpable
Dumpable.DumpableContainer
-
Nested classes/interfaces inherited from interface org.eclipse.jetty.util.thread.ExecutionStrategy
ExecutionStrategy.Producer
-
Nested classes/interfaces inherited from interface org.eclipse.jetty.util.component.LifeCycle
LifeCycle.Listener
-
-
Field Summary
Fields Modifier and Type Field Description private java.util.concurrent.atomic.LongAdder_epcModeprivate java.util.concurrent.Executor_executorprivate java.util.concurrent.atomic.LongAdder_pcModeprivate java.util.concurrent.atomic.LongAdder_pecModeprivate boolean_pendingprivate java.util.concurrent.atomic.LongAdder_picModeprivate ExecutionStrategy.Producer_producerprivate EatWhatYouKill.State_stateprivate TryExecutor_tryExecutorprivate static LoggerLOG
-
Constructor Summary
Constructors Constructor Description EatWhatYouKill(ExecutionStrategy.Producer producer, java.util.concurrent.Executor executor)
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description voiddispatch()Initiates (or resumes) the task production and consumption.private booleandoProduce(boolean nonBlocking)private voidexecute(java.lang.Runnable task)longgetEPCTasksConsumed()longgetPCTasksConsumed()longgetPECTasksExecuted()longgetPICTasksExecuted()private voidgetState(java.lang.StringBuilder builder)private voidgetString(java.lang.StringBuilder builder)private voidinvokeTask(java.lang.Runnable task)booleanisIdle()voidproduce()Initiates (or resumes) the task production and consumption.private java.lang.RunnableproduceTask()voidreset()voidrun()private voidrunTask(java.lang.Runnable task)java.lang.StringtoString()java.lang.StringtoStringLocked()private voidtryProduce(boolean wasPending)-
Methods inherited from class org.eclipse.jetty.util.component.ContainerLifeCycle
addBean, addBean, addEventListener, addManaged, contains, destroy, doStart, doStop, dump, dump, dump, dump, dump, dumpBeans, dumpObject, dumpObjects, dumpStdErr, dumpThis, getBean, getBeans, getBeans, getContainedBeans, getContainedBeans, isAuto, isManaged, isUnmanaged, manage, removeBean, removeBeans, removeEventListener, setBeans, setStopTimeout, start, stop, unmanage, updateBean, updateBean, updateBeans
-
Methods inherited from class org.eclipse.jetty.util.component.AbstractLifeCycle
addLifeCycleListener, getState, getState, getStopTimeout, isFailed, isRunning, isStarted, isStarting, isStopped, isStopping, removeLifeCycleListener, start, stop
-
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
-
Methods inherited from interface org.eclipse.jetty.util.component.Dumpable.DumpableContainer
isDumpable
-
-
-
-
Field Detail
-
LOG
private static final Logger LOG
-
_pcMode
private final java.util.concurrent.atomic.LongAdder _pcMode
-
_picMode
private final java.util.concurrent.atomic.LongAdder _picMode
-
_pecMode
private final java.util.concurrent.atomic.LongAdder _pecMode
-
_epcMode
private final java.util.concurrent.atomic.LongAdder _epcMode
-
_producer
private final ExecutionStrategy.Producer _producer
-
_executor
private final java.util.concurrent.Executor _executor
-
_tryExecutor
private final TryExecutor _tryExecutor
-
_state
private EatWhatYouKill.State _state
-
_pending
private boolean _pending
-
-
Constructor Detail
-
EatWhatYouKill
public EatWhatYouKill(ExecutionStrategy.Producer producer, java.util.concurrent.Executor executor)
-
-
Method Detail
-
dispatch
public void dispatch()
Description copied from interface:ExecutionStrategyInitiates (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)- Specified by:
dispatchin interfaceExecutionStrategy- See Also:
ExecutionStrategy.produce()
-
run
public void run()
- Specified by:
runin interfacejava.lang.Runnable
-
produce
public void produce()
Description copied from interface:ExecutionStrategyInitiates (or resumes) the task production and consumption.
The produced task may be run by the same thread that called this method.
- Specified by:
producein interfaceExecutionStrategy- See Also:
ExecutionStrategy.dispatch()
-
tryProduce
private void tryProduce(boolean wasPending)
-
doProduce
private boolean doProduce(boolean nonBlocking)
-
runTask
private void runTask(java.lang.Runnable task)
-
invokeTask
private void invokeTask(java.lang.Runnable task)
-
produceTask
private java.lang.Runnable produceTask()
-
execute
private void execute(java.lang.Runnable task)
-
getPCTasksConsumed
@ManagedAttribute(value="number of tasks consumed with PC mode", readonly=true) public long getPCTasksConsumed()
-
getPICTasksExecuted
@ManagedAttribute(value="number of tasks executed with PIC mode", readonly=true) public long getPICTasksExecuted()
-
getPECTasksExecuted
@ManagedAttribute(value="number of tasks executed with PEC mode", readonly=true) public long getPECTasksExecuted()
-
getEPCTasksConsumed
@ManagedAttribute(value="number of tasks consumed with EPC mode", readonly=true) public long getEPCTasksConsumed()
-
isIdle
@ManagedAttribute(value="whether this execution strategy is idle", readonly=true) public boolean isIdle()
-
reset
@ManagedOperation(value="resets the task counts", impact="ACTION") public void reset()
-
toString
public java.lang.String toString()
- Overrides:
toStringin classAbstractLifeCycle
-
toStringLocked
public java.lang.String toStringLocked()
-
getString
private void getString(java.lang.StringBuilder builder)
-
getState
private void getState(java.lang.StringBuilder builder)
-
-