java.lang.Runnable, ExecutionStrategypublic class ExecuteProduceConsume extends ExecutingExecutionStrategy 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.
| Modifier and Type | Class | Description |
|---|---|---|
static class |
ExecuteProduceConsume.Factory |
ExecutionStrategy.DefaultExecutionStrategyFactory, ExecutionStrategy.Producer, ExecutionStrategy.Rejectable| Constructor | Description |
|---|---|
ExecuteProduceConsume(ExecutionStrategy.Producer producer,
java.util.concurrent.Executor executor) |
|
ExecuteProduceConsume(ExecutionStrategy.Producer producer,
java.util.concurrent.Executor executor,
ExecutionStrategy lowResourceStrategy) |
Deprecated.
|
| Modifier and Type | Method | Description |
|---|---|---|
void |
dispatch() |
Initiates (or resumes) the task production and execution.
|
void |
execute() |
Initiates (or resumes) the task production and execution.
|
protected void |
executeProduct(java.lang.Runnable task) |
Only called when in
low threads mode
to execute the task produced by the producer. |
java.lang.Boolean |
isIdle() |
|
boolean |
isLowOnThreads() |
|
void |
run() |
|
java.lang.String |
toString() |
executepublic ExecuteProduceConsume(ExecutionStrategy.Producer producer, java.util.concurrent.Executor executor)
@Deprecated public ExecuteProduceConsume(ExecutionStrategy.Producer producer, java.util.concurrent.Executor executor, ExecutionStrategy lowResourceStrategy)
public void execute()
ExecutionStrategyInitiates (or resumes) the task production and execution.
The produced task may be run by the same thread that called this method.
execute in interface ExecutionStrategyExecutionStrategy.dispatch()public void dispatch()
ExecutionStrategyInitiates (or resumes) the task production and execution.
This method guarantees that the task is never run by the thread that called this method.
dispatch in interface ExecutionStrategyExecutionStrategy.execute()public void run()
run in interface java.lang.Runnablepublic boolean isLowOnThreads()
protected void executeProduct(java.lang.Runnable task)
Only called when in low threads mode
to execute the task produced by the producer.
Because
If the task implements ExecutionStrategy.Rejectable, then ExecutionStrategy.Rejectable.reject()
is immediately called on the task object. If the task also implements
Closeable, then Closeable.close() is called on the task object.
If the task does not implement ExecutionStrategy.Rejectable, then it is
executed.
task - the produced task to executepublic java.lang.Boolean isIdle()
public java.lang.String toString()
toString in class java.lang.ObjectCopyright © 1995–2018 Webtide. All rights reserved.