Esempio n. 1
0
  public boolean cancel(boolean mayInterruptIfRunning) {
    if (future == null)
      throw new UnsupportedOperationException(
          "You cannot cancel this task before calling future()");

    return future.cancel(mayInterruptIfRunning);
  }
Esempio n. 2
0
  protected <T> T timedCall(Callable<T> c, long timeout, TimeUnit timeUnit)
      throws InterruptedException, ExecutionException, TimeoutException {

    FutureTask<T> task = new FutureTask<T>(c);
    try {
      THREAD_POOL.execute(task);
      return task.get(timeout, timeUnit);
    } finally {
      task.cancel(true);
    }
  }