/** * Submits a Runnable task for execution and returns a Future * representing that task. Upon completion, this task may be * taken or polled. * * @param task the task to submit * @return a future to watch the task */ public Future<?> submit(Runnable task) { Preconditions.checkState(isOpen.get(), "CloseableExecutorService is closed"); InternalFutureTask<Void> futureTask = new InternalFutureTask<Void>(new FutureTask<Void>(task, null)); executorService.execute(futureTask); return futureTask; } }
/** * Creates and executes a one-shot action that becomes enabled * after the given delay. * * @param task the task to execute * @param delay the time from now to delay execution * @param unit the time unit of the delay parameter * @return a Future representing pending completion of * the task and whose <tt>get()</tt> method will return * <tt>null</tt> upon completion */ public Future<?> schedule(Runnable task, long delay, TimeUnit unit) { Preconditions.checkState(isOpen.get(), "CloseableExecutorService is closed"); InternalFutureTask<Void> futureTask = new InternalFutureTask<Void>(new FutureTask<Void>(task, null)); scheduledExecutorService.schedule(futureTask, delay, unit); return futureTask; }
/** * Submits a Runnable task for execution and returns a Future * representing that task. Upon completion, this task may be * taken or polled. * * @param task the task to submit * @return a future to watch the task */ public Future<?> submit(Runnable task) { Preconditions.checkState(isOpen.get(), "CloseableExecutorService is closed"); InternalFutureTask<Void> futureTask = new InternalFutureTask<Void>(new FutureTask<Void>(task, null)); executorService.execute(futureTask); return futureTask; } }
/** * Creates and executes a one-shot action that becomes enabled * after the given delay. * * @param task the task to execute * @param delay the time from now to delay execution * @param unit the time unit of the delay parameter * @return a Future representing pending completion of * the task and whose <tt>get()</tt> method will return * <tt>null</tt> upon completion */ public Future<?> schedule(Runnable task, long delay, TimeUnit unit) { Preconditions.checkState(isOpen.get(), "CloseableExecutorService is closed"); InternalFutureTask<Void> futureTask = new InternalFutureTask<Void>(new FutureTask<Void>(task, null)); scheduledExecutorService.schedule(futureTask, delay, unit); return futureTask; }
/** * Submits a value-returning task for execution and returns a Future * representing the pending results of the task. Upon completion, * this task may be taken or polled. * * @param task the task to submit * @return a future to watch the task */ public<V> Future<V> submit(Callable<V> task) { Preconditions.checkState(isOpen.get(), "CloseableExecutorService is closed"); InternalFutureTask<V> futureTask = new InternalFutureTask<V>(new FutureTask<V>(task)); executorService.execute(futureTask); return futureTask; }
/** * Submits a value-returning task for execution and returns a Future * representing the pending results of the task. Upon completion, * this task may be taken or polled. * * @param task the task to submit * @return a future to watch the task */ public<V> Future<V> submit(Callable<V> task) { Preconditions.checkState(isOpen.get(), "CloseableExecutorService is closed"); InternalFutureTask<V> futureTask = new InternalFutureTask<V>(new FutureTask<V>(task)); executorService.execute(futureTask); return futureTask; }