public class CancellableTask<T> extends Object implements Runnable
Runnables that have state to be cleared at the end of their execution.
This is simpler than CompletableFuture and the cancel() method is useful when the task has to
be cancelled - even when it has not been scheduled.
If the ExecutorService.submit(Runnable) fails then the task can simply be cancelled and
resources can be cleaned up.
Also see cancel().
The end could be due to:
- Success
- Failure - if the task has been cancelled or the task executed but encountered an error.
Created by ashwin.jayaprakash.
public void run()
run in interface RunnableIllegalStateException - If the task was already done or cancelled before.public void cancel()
- The failure task is called with CancellationException if the task was never started.
- Or, cancels an already running task by interrupting that thread but not when it is running the failure/success
task. Like FutureTask this call does not wait for the main thread to complete and return, but merely
interrupts it and returns.
Copyright © 2018. All rights reserved.