public T get(long timeout, TimeUnit unit) throws InterruptedException, ExecutionException, TimeoutException { await(timeout, unit); Object result = this.result; if (failure) throw new ExecutionException((Throwable) result); return (T) result; } }
public void run() { try { result = callable.call(); } catch (Throwable t) { JVMStabilityInspector.inspectThrowable(t); logger.warn("Uncaught exception on thread {}: {}", Thread.currentThread(), t); result = t; failure = true; } finally { signalAll(); onCompletion(); } }
public void maybeExecuteImmediately(Runnable command) { FutureTask<?> ft = newTaskFor(command, null); if (!takeWorkPermit(false)) { addTask(ft); } else { try { ft.run(); } finally { returnWorkPermit(); // we have to maintain our invariant of always scheduling after any work is performed // in this case in particular we are not processing the rest of the queue anyway, and so // the work permit may go wasted if we don't immediately attempt to spawn another worker maybeSchedule(); } } }
public void run() { TraceState oldState = Tracing.instance.get(); Tracing.instance.set(state); try { super.run(); } finally { Tracing.instance.set(oldState); } } }
public T get() throws InterruptedException, ExecutionException { await(); Object result = this.result; if (failure) throw new ExecutionException((Throwable) result); return (T) result; }
protected <T> FutureTask<T> newTaskFor(Runnable runnable, T result, TraceState traceState) { if (traceState != null) { if (runnable instanceof TraceSessionFutureTask) return (TraceSessionFutureTask<T>) runnable; return new TraceSessionFutureTask<T>(runnable, result, traceState); } if (runnable instanceof FutureTask) return (FutureTask<T>) runnable; return new FutureTask<>(runnable, result); }
public boolean isDone() { return isSignaled(); }
protected <T> FutureTask<T> newTaskFor(Callable<T> callable) { if (isTracing()) { if (callable instanceof TraceSessionFutureTask) return (TraceSessionFutureTask<T>) callable; return new TraceSessionFutureTask<T>(callable, Tracing.instance.get()); } if (callable instanceof FutureTask) return (FutureTask<T>) callable; return new FutureTask<>(callable); }