GeezerVison is showing docs.oracle.com — FutureTask (Java Platform SE 8 )
Java™ Platform Standard Ed. 8
compact1, compact2, compact3
java.util.concurrent
Class FutureTask<V>
-
-
Constructor Summary
Constructors
| Constructor |
Description |
FutureTask(Callable<V> callable) |
Creates a FutureTask that will, upon running, execute the
given Callable.
|
FutureTask(Runnable runnable,
V result) |
Creates a FutureTask that will, upon running, execute the
given Runnable, and arrange that get will return the
given result on successful completion.
|
-
Method Summary
All Methods Instance Methods Concrete Methods
| Modifier and Type |
Method |
Description |
boolean |
cancel(boolean mayInterruptIfRunning) |
Attempts to cancel execution of this task.
|
protected void |
done() |
Protected method invoked when this task transitions to state
isDone (whether normally or via cancellation).
|
V |
get() |
Waits if necessary for the computation to complete, and then
retrieves its result.
|
V |
get(long timeout,
TimeUnit unit) |
Waits if necessary for at most the given time for the computation
to complete, and then retrieves its result, if available.
|
boolean |
isCancelled() |
Returns true if this task was cancelled before it completed
normally.
|
boolean |
isDone() |
Returns true if this task completed.
|
void |
run() |
Sets this Future to the result of its computation
unless it has been cancelled.
|
protected boolean |
runAndReset() |
Executes the computation without setting its result, and then
resets this future to initial state, failing to do so if the
computation encounters an exception or is cancelled.
|
protected void |
set(V v) |
Sets the result of this future to the given value unless
this future has already been set or has been cancelled.
|
protected void |
setException(Throwable t) |
Causes this future to report an ExecutionException
with the given throwable as its cause, unless this future has
already been set or has been cancelled.
|
-
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
-
-
Constructor Detail
-
FutureTask
public FutureTask(Callable<V> callable)
Creates a FutureTask that will, upon running, execute the
given Callable.
- Parameters:
callable - the callable task
- Throws:
NullPointerException - if the callable is null
-
FutureTask
public FutureTask(Runnable runnable,
V result)
Creates a FutureTask that will, upon running, execute the
given Runnable, and arrange that get will return the
given result on successful completion.
- Parameters:
runnable - the runnable task
result - the result to return on successful completion. If
you don't need a particular result, consider using
constructions of the form:
Future<?> f = new FutureTask<Void>(runnable, null)
- Throws:
NullPointerException - if the runnable is null
-
Method Detail
-
isDone
public boolean isDone()
Description copied from interface: Future
Returns true if this task completed.
Completion may be due to normal termination, an exception, or
cancellation -- in all of these cases, this method will return
true.
- Specified by:
isDone in interface Future<V>
- Returns:
true if this task completed
-
set
protected void set(V v)
Sets the result of this future to the given value unless
this future has already been set or has been cancelled.
This method is invoked internally by the run() method
upon successful completion of the computation.
- Parameters:
v - the value
-
runAndReset
protected boolean runAndReset()
Executes the computation without setting its result, and then
resets this future to initial state, failing to do so if the
computation encounters an exception or is cancelled. This is
designed for use with tasks that intrinsically execute more
than once.
- Returns:
true if successfully run and reset
Java™ Platform Standard Ed. 8
Submit a bug or feature For further API reference and developer documentation, see Java SE Documentation. That documentation contains more detailed, developer-targeted descriptions, with conceptual overviews, definitions of terms, workarounds, and working code examples. Copyright © 1993, 2026, Oracle and/or its affiliates. All rights reserved. Use is subject to license terms. Also see the documentation redistribution policy.
|