public synchronized void set(Object result) { super.set(result); }
/** * Returns a <tt>RunnableFuture</tt> for the given callable task. * * @param callable the callable task being wrapped * @return a <tt>RunnableFuture</tt> which when run will call the * underlying callable and which, as a <tt>Future</tt>, will yield * the callable's result as its result and provide for * cancellation of the underlying task. * @since 1.6 */ protected RunnableFuture newTaskFor(Callable callable) { return new FutureTask(callable); }
public boolean cancel(boolean mayInterruptIfRunning) { synchronized (this) { if (ranOrCancelled()) return false; state = CANCELLED; if (mayInterruptIfRunning) { Thread r = runner; if (r != null) r.interrupt(); } runner = null; notifyAll(); } done(); return true; }
/** * Sets this Future to the result of its computation * unless it has been cancelled. */ public void run() { synchronized (this) { if (state != READY) return; state = RUNNING; runner = Thread.currentThread(); } try { set(callable.call()); } catch (Throwable ex) { setException(ex); } }
/** * Overrides FutureTask version so as to reset/requeue if periodic. */ public void run() { boolean periodic = isPeriodic(); if (!canRunInCurrentRunState(periodic)) cancel(false); else if (!periodic) ScheduledFutureTask.super.run(); else if (ScheduledFutureTask.super.runAndReset()) { setNextRunTime(); reExecutePeriodic(this); } } }
/** * Waits for the task to complete. * PRE: lock owned */ private void waitFor() throws InterruptedException { while (!isDone()) { wait(); } }
public boolean cancel(boolean mayInterruptIfRunning) { boolean cancelled = super.cancel(mayInterruptIfRunning); if (cancelled && removeOnCancel && heapIndex >= 0) remove(this); return cancelled; }
/** * Sets the result of this Future to the given value unless * this future has already been set or has been cancelled. * This method is invoked internally by the <tt>run</tt> method * upon successful completion of the computation. * @param v the value */ protected void set(Object v) { setCompleted(v); }
public synchronized boolean isDone() { return ranOrCancelled() && runner == null; }
/** * Sets this Future to the result of its computation * unless it has been cancelled. */ public void run() { synchronized (this) { if (state != READY) return; state = RUNNING; runner = Thread.currentThread(); } try { set(callable.call()); } catch (Throwable ex) { setException(ex); } }
/** * Overrides FutureTask version so as to reset/requeue if periodic. */ public void run() { boolean periodic = isPeriodic(); if (!canRunInCurrentRunState(periodic)) cancel(false); else if (!periodic) ScheduledFutureTask.super.run(); else if (ScheduledFutureTask.super.runAndReset()) { setNextRunTime(); reExecutePeriodic(this); } } }
/** * Waits for the task to complete. * PRE: lock owned */ private void waitFor() throws InterruptedException { while (!isDone()) { wait(); } }
public boolean cancel(boolean mayInterruptIfRunning) { boolean cancelled = super.cancel(mayInterruptIfRunning); if (cancelled && removeOnCancel && heapIndex >= 0) remove(this); return cancelled; }
/** * Sets the result of this Future to the given value unless * this future has already been set or has been cancelled. * This method is invoked internally by the <tt>run</tt> method * upon successful completion of the computation. * @param v the value */ protected void set(Object v) { setCompleted(v); }
public synchronized boolean isDone() { return ranOrCancelled() && runner == null; }
/** * Marks the task as failed. * @param exception the cause of abrupt completion. */ private void setFailed(Throwable exception) { synchronized (this) { if (ranOrCancelled()) return; this.state = RAN; this.exception = exception; this.runner = null; notifyAll(); } // invoking callbacks *after* setting future as completed and // outside the synchronization block makes it safe to call // interrupt() from within callback code (in which case it will be // ignored rather than cause deadlock / illegal state exception) done(); }
/** * Sets this Future to the result of its computation * unless it has been cancelled. */ public void run() { synchronized (this) { if (state != READY) return; state = RUNNING; runner = Thread.currentThread(); } try { set(callable.call()); } catch (Throwable ex) { setException(ex); } }