@Override protected void done() { run(onComplete); }
@Override protected void done() { run(onComplete); }
@Override protected void done() { run(onComplete); }
public static NotifyingFutureTask completed() { NotifyingFutureTask f = new NotifyingFutureTask(NOP); f.run(); return f; } }
public static NotifyingFutureTask completed() { NotifyingFutureTask f = new NotifyingFutureTask(NOP); f.run(); return f; } }
public static NotifyingFutureTask completed() { NotifyingFutureTask f = new NotifyingFutureTask(NOP); f.run(); return f; } }
/** * Set the on complete handler. The handler will run exactly once after * the task terminated. If the task has already terminated at the time of * this method call the handler will execute immediately. * <p> * Note: there is no guarantee to which handler will run when the method * is called multiple times with different arguments. * </p> * @param onComplete listener to invoke upon completion */ public void onComplete(Runnable onComplete) { this.onComplete = onComplete; if (isDone()) { run(onComplete); } }
/** * Set the on complete handler. The handler will run exactly once after * the task terminated. If the task has already terminated at the time of * this method call the handler will execute immediately. * <p> * Note: there is no guarantee to which handler will run when the method * is called multiple times with different arguments. * </p> * @param onComplete listener to invoke upon completion */ public void onComplete(Runnable onComplete) { this.onComplete = onComplete; if (isDone()) { run(onComplete); } }
/** * Set the on complete handler. The handler will run exactly once after * the task terminated. If the task has already terminated at the time of * this method call the handler will execute immediately. * <p> * Note: there is no guarantee to which handler will run when the method * is called multiple times with different arguments. * </p> * @param onComplete listener to invoke upon completion */ public void onComplete(Runnable onComplete) { this.onComplete = onComplete; if (isDone()) { run(onComplete); } }
@Test public void onCompletion() throws Exception{ CountingCallable callable = new CountingCallable(); CountingRunnable runnable = new CountingRunnable(); NotifyingFutureTask nft = new NotifyingFutureTask(callable); nft.onComplete(runnable); nft.run(); assertEquals(1, callable.count); assertEquals(1, runnable.count); nft.run(); assertEquals("Callback should be invoked only once", 1, runnable.count); }