Bah humbug

This commit is contained in:
Greg Wilkins 2014-12-25 10:21:20 +01:00
parent a89a6927e8
commit fd605248dc
1 changed files with 31 additions and 0 deletions

View File

@ -56,6 +56,37 @@ public interface ExecutionStrategy
Runnable produce();
}
/**
* <p>A strategy where the caller thread iterates over task production, submitting each
* task to an {@link Executor} for execution.</p>
*/
public static class ProduceRun implements ExecutionStrategy
{
private final Producer _producer;
public ProduceRun(Producer producer)
{
this._producer = producer;
}
@Override
public void execute()
{
// Iterate until we are complete.
while (true)
{
// Produce a task.
Runnable task = _producer.produce();
if (task == null)
break;
// run the task.
task.run();
}
}
}
/**
* <p>A strategy where the caller thread iterates over task production, submitting each
* task to an {@link Executor} for execution.</p>