Scheduler scheduler = null;
synchronized (schedulerAtomLock) {
scheduler = schedulerAtom.get();
if (scheduler == null) terminateSchedulerWhenPossible = true;
}
if (scheduler != null) scheduler.terminate();
}
Scheduler getScheduler() {
return schedulerAtom.get();