Class CompletableFutureTask<R>

    • Constructor Detail

      • CompletableFutureTask

        public CompletableFutureTask​(Callable<R> task)
        Creates a completable future bound to the specified task. This task will be executed on a call to run(), for instance by submitting this object to an Executor.
        Parameters:
        task - The task to be bound to this future.
    • Method Detail

      • run

        public void run()
        Executes the wrapped callable. On execution end, this future will complete with the callable result, or complete exceptionally in case of exception.
        Specified by:
        run in interface Runnable
      • runAsync

        public CompletableFutureTask<R> runAsync​(Executor executor)
        Submits this task to the specified executor.
        Parameters:
        executor - The executor which will execute this task.
        Returns:
        This.
      • runAsync

        public static <T> CompletableFutureTask<T> runAsync​(Callable<T> task,
                                                            Executor executor)
        Creates a completable future task and submits it to the specified executor.
        Parameters:
        task - The task to be executed.
        executor - The executor which will execute the task.
        Returns:
        A CompletableFutureTask bound to the specified task.
      • cancel

        public boolean cancel​(boolean mayInterruptIfRunning)
        Cancels this completable future and, if requested and if the bound task is under execution, interrupts the thread executing the task.
        Specified by:
        cancel in interface Future<R>
        Overrides:
        cancel in class CompletableFuture<R>
        Parameters:
        mayInterruptIfRunning - if true, and if the bound task is under execution, the thread executing the task will be interrupted
        Returns:
        false if the task could not be cancelled, typically because it has already completed; true otherwise