Class ExecuteProduceConsume
- java.lang.Object
-
- org.eclipse.jetty.util.thread.strategy.ExecuteProduceConsume
-
- All Implemented Interfaces:
java.lang.Runnable
,ExecutionStrategy
public class ExecuteProduceConsume extends java.lang.Object implements ExecutionStrategy, java.lang.Runnable
A strategy where the thread that produces will always run the resulting task.
The strategy may then dispatch another thread to continue production.
The strategy is also known by the nickname 'eat what you kill', which comes from the hunting ethic that says a person should not kill anything he or she does not plan on eating. In this case, the phrase is used to mean that a thread should not produce a task that it does not intend to run. By making producers run the task that they have just produced avoids execution delays and avoids parallel slow down by running the task in the same core, with good chances of having a hot CPU cache. It also avoids the creation of a queue of produced tasks that the system does not yet have capacity to consume, which can save memory and exert back pressure on producers.
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description private class
ExecuteProduceConsume.RunProduce
-
Nested classes/interfaces inherited from interface org.eclipse.jetty.util.thread.ExecutionStrategy
ExecutionStrategy.Producer
-
-
Field Summary
Fields Modifier and Type Field Description private boolean
_execute
private java.util.concurrent.Executor
_executor
private boolean
_idle
private Locker
_locker
private boolean
_pending
private ExecutionStrategy.Producer
_producer
private boolean
_producing
private java.lang.Runnable
_runProduce
private static Logger
LOG
-
Constructor Summary
Constructors Constructor Description ExecuteProduceConsume(ExecutionStrategy.Producer producer, java.util.concurrent.Executor executor)
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description void
dispatch()
Initiates (or resumes) the task production and consumption.java.lang.Boolean
isIdle()
void
produce()
Initiates (or resumes) the task production and consumption.private void
produceConsume()
void
run()
java.lang.String
toString()
-
-
-
Field Detail
-
LOG
private static final Logger LOG
-
_locker
private final Locker _locker
-
_runProduce
private final java.lang.Runnable _runProduce
-
_producer
private final ExecutionStrategy.Producer _producer
-
_executor
private final java.util.concurrent.Executor _executor
-
_idle
private boolean _idle
-
_execute
private boolean _execute
-
_producing
private boolean _producing
-
_pending
private boolean _pending
-
-
Constructor Detail
-
ExecuteProduceConsume
public ExecuteProduceConsume(ExecutionStrategy.Producer producer, java.util.concurrent.Executor executor)
-
-
Method Detail
-
produce
public void produce()
Description copied from interface:ExecutionStrategy
Initiates (or resumes) the task production and consumption.
The produced task may be run by the same thread that called this method.
- Specified by:
produce
in interfaceExecutionStrategy
- See Also:
ExecutionStrategy.dispatch()
-
dispatch
public void dispatch()
Description copied from interface: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)- Specified by:
dispatch
in interfaceExecutionStrategy
- See Also:
ExecutionStrategy.produce()
-
run
public void run()
- Specified by:
run
in interfacejava.lang.Runnable
-
produceConsume
private void produceConsume()
-
isIdle
public java.lang.Boolean isIdle()
-
toString
public java.lang.String toString()
- Overrides:
toString
in classjava.lang.Object
-
-