taskScheduled.setJob(new Callable() { @Override public Object call() { boolean shouldResubmit = true; task.recentRun = taskScheduledF; try { synchronized (task) { task.notifyAll(); } Object result; try { result = oldJob.call(); task.lastThrownType = null; } catch (Exception e) { shouldResubmit = shouldResubmitOnException(oldJob, e); throw Exceptions.propagate(e); } return result; } finally { // do in finally block in case we were interrupted if (shouldResubmit) { resubmit(); } else { afterEndScheduledTaskAllIterations(flags, task); } } }}); task.nextRun = taskScheduled;
protected Task<?> submitSubsequentScheduledTask(final Map<?,?> flags, final ScheduledTask task) { if (!task.isDone()) { task.internalFuture = delayedRunner.schedule(new ScheduledTaskCallable(task, flags), task.delay.toNanoseconds(), TimeUnit.NANOSECONDS); } else { afterEndScheduledTaskAllIterations(flags, task); } return task; }