public class ExecuteProduceConsume extends Object implements ExecutionStrategy, Runnable
A strategy where the thread calls produce will always run the resulting task itself. The strategy may dispatches 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.
ExecutionStrategy.Factory, ExecutionStrategy.Producer
Constructor and Description |
---|
ExecuteProduceConsume(ExecutionStrategy.Producer producer,
Executor executor) |
Modifier and Type | Method and Description |
---|---|
void |
dispatch()
Initiates (or resumes) the task production and execution.
|
void |
execute()
Initiates (or resumes) the task production and execution.
|
Boolean |
isIdle() |
void |
run() |
String |
toString() |
public ExecuteProduceConsume(ExecutionStrategy.Producer producer, Executor executor)
public void execute()
ExecutionStrategy
Initiates (or resumes) the task production and execution.
The produced task may be run by the same thread that called this method.
execute
in interface ExecutionStrategy
ExecutionStrategy.dispatch()
public void dispatch()
ExecutionStrategy
Initiates (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 ExecutionStrategy
ExecutionStrategy.execute()
public Boolean isIdle()
Copyright © 1995-2015 Webtide. All Rights Reserved.