...
Code Block | ||||
---|---|---|---|---|
| ||||
final class CompletedTaskHandler implements EventHandler<CompletedTask> { @Override public void onNext(final CompletedTask task) { final int taskId = Integer.valueOf(task.getId()); synchronized (SchedulerDriver.this) { ... final ActiveContext context = task.getActiveContext(); if (retainable) { retainEvaluator(context); } else { reallocateEvaluator(context); } ... } } |
In the CompletedTaskHandler, the active Context can be accessed from the `CompletedTask` object, which makes it possible to reuse the Evaluator.
Code Block | ||||
---|---|---|---|---|
| ||||
private synchronized void retainEvaluator(final ActiveContext context) {
if (scheduler.hasPendingTasks()) {
scheduler.submitTask(context);
} else if (nActiveEval > 1) {
nActiveEval--;
context.close();
} else {
state = State.READY;
waitForCommands(context);
}
} |
In the `ratainEvaluator()` method, `scheduler.submitTask(context)` makes the Evaluator run another Task if there is a pending Task. Otherwise, the Evaluator is relaesed by closing the active Context, or waits until a new command arrives.
To turn off this feature, add command line argument `-retain false` when you launch the application: Evaluators are released when Tasks end, and a new Evaluator is allocated whenever a Task starts.