Overview of the Future class works #74
pwgit-create
announced in
PWSS-DirectoryNav
Replies: 0 comments
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Uh oh!
There was an error while loading. Please reload this page.
-
Key Concepts
blocked waiting for the task to complete.
Important Methods
get(): Blocks until the computation is done and then returns the result.InterruptedExceptionif the current thread is interrupted while waiting.ExecutionExceptionif the computation threw an exception.CancellationExceptionif the computation was cancelled.isDone(): Returnstrueif the computation has completed, either normally or by throwing an exception.cancel(boolean mayInterruptIfRunning): Attempts to cancel the execution of this task. IfmayInterruptIfRunningis true and the thread running the task is interruptible, it will be interrupted.Example Usage
Let's look at a simple example that demonstrates how to use the
Future:Key Points:
Runnable, but it returns a result (unlikeRunnablewhich does not returnanything).
Real-World Usage:
future.cancel(boolean mayInterruptIfRunning).isDone().Beta Was this translation helpful? Give feedback.
All reactions