Source:
protected <T> Task<T> submitNewTask(final Map flags, final Task<T> task) { if (task instanceof ScheduledTask) return submitNewScheduledTask(flags, (ScheduledTask)task); totalTaskCount.incrementAndGet(); beforeSubmit(flags, task); assert ((BasicTask)task).job != null : "submission of task "+task+" with null job"; Callable job = new Callable() { public Object call() { Object result = null; String oldThreadName = Thread.currentThread().getName(); try { if (RENAME_THREADS) { String newThreadName = oldThreadName+"-"+task.getDisplayName()+ "["+task.getId().substring(0, 8)+"]"; Thread.currentThread().setName(newThreadName); } beforeStart(flags, task); if (!task.isCancelled()) { result = ((BasicTask)task).job.call(); } else throw new CancellationException(); } catch(Throwable e) { result = e; } finally { if (RENAME_THREADS) { Thread.currentThread().setName(oldThreadName); } afterEnd(flags, task); } if (result instanceof Throwable) { log.warn("Error while running task "+task+" (rethrowing): "+((Throwable)result).getMessage(), (Throwable)result); throw Throwables.propagate((Throwable)result); } return result; }}; ((BasicTask)task).initExecutionManager(this); Set<TaskScheduler> schedulers = null; for (Object tago: ((BasicTask)task).tags) { TaskScheduler scheduler = getTaskSchedulerForTag(tago); if (scheduler!=null) { if (schedulers==null) schedulers = new LinkedHashSet(2); schedulers.add(scheduler); } } Future future; if (schedulers!=null && !schedulers.isEmpty()) { if (schedulers.size()>1) log.warn("multiple schedulers detected, using only the first, for "+task+": "+schedulers); future = schedulers.iterator().next().submit(job); } else { future = runner.submit(job); } ((BasicTask)task).initResult(future); return task; }

Target:
protected <T> Task<T> submitNewTask(final Map flags, final Task<T> task) { if (task instanceof ScheduledTask) return submitNewScheduledTask(flags, (ScheduledTask)task); totalTaskCount.incrementAndGet(); beforeSubmit(flags, task); if (((BasicTask)task).job==null) throw new NullPointerException("Task "+task+" submitted with with null job: job must be supplied."); Callable job = new Callable() { public Object call() { Object result = null; Throwable error = null; String oldThreadName = Thread.currentThread().getName(); try { if (RENAME_THREADS) { String newThreadName = oldThreadName+"-"+task.getDisplayName()+ "["+task.getId().substring(0, 8)+"]"; Thread.currentThread().setName(newThreadName); } beforeStart(flags, task); if (!task.isCancelled()) { result = ((BasicTask)task).job.call(); } else throw new CancellationException(); } catch(Throwable e) { error = e; } finally { if (RENAME_THREADS) { Thread.currentThread().setName(oldThreadName); } afterEnd(flags, task); } if (error!=null) { log.warn("Error while running task "+task+" (rethrowing): "+error.getMessage(), error); throw Throwables.propagate(error); } return result; }}; ((BasicTask)task).initExecutionManager(this); Set<TaskScheduler> schedulers = null; for (Object tago: ((BasicTask)task).tags) { TaskScheduler scheduler = getTaskSchedulerForTag(tago); if (scheduler!=null) { if (schedulers==null) schedulers = new LinkedHashSet(2); schedulers.add(scheduler); } } Future future; if (schedulers!=null && !schedulers.isEmpty()) { if (schedulers.size()>1) log.warn("multiple schedulers detected, using only the first, for "+task+": "+schedulers); future = schedulers.iterator().next().submit(job); } else { future = runner.submit(job); } ((BasicTask)task).initResult(future); return task; }