Package org.sosy_lab.common
Class LazyFutureTask<V extends @Nullable Object>
- java.lang.Object
-
- java.util.concurrent.FutureTask<V>
-
- org.sosy_lab.common.LazyFutureTask<V>
-
- All Implemented Interfaces:
Runnable
,Future<V>
,RunnableFuture<V>
public class LazyFutureTask<V extends @Nullable Object> extends FutureTask<V>
Future implementation that can be used when a task should be executed only lazily at the first timeget()
is called. I.e., it is not guaranteed that the task is run at all, but it is called at most once.Execution of the task happens in the caller's thread, a little bit similar to the use of
MoreExecutors.newDirectExecutorService()
, however, it is executed on the thread callingget()
and not on the thread callingExecutorService.submit(Callable)
.Important: Calling
get(long, TimeUnit)
is not supported and will always throwUnsupportedOperationException
.Canceling this future works as expected.
-
-
Constructor Summary
Constructors Constructor Description LazyFutureTask(Runnable pRunnable, V pResult)
LazyFutureTask(Callable<V> pCallable)
-
Method Summary
All Methods Instance Methods Concrete Methods Deprecated Methods Modifier and Type Method Description V
get()
V
get(long pTimeout, TimeUnit pUnit)
Deprecated.Unsupported operation.void
run()
-
Methods inherited from class java.util.concurrent.FutureTask
cancel, done, isCancelled, isDone, runAndReset, set, setException, toString
-
-
-
-
Method Detail
-
run
public void run()
- Specified by:
run
in interfaceRunnable
- Specified by:
run
in interfaceRunnableFuture<V extends @Nullable Object>
- Overrides:
run
in classFutureTask<V extends @Nullable Object>
-
get
public V get() throws InterruptedException, ExecutionException
- Specified by:
get
in interfaceFuture<V extends @Nullable Object>
- Overrides:
get
in classFutureTask<V extends @Nullable Object>
- Throws:
InterruptedException
ExecutionException
-
get
@Deprecated public V get(long pTimeout, TimeUnit pUnit)
Deprecated.Unsupported operation.- Specified by:
get
in interfaceFuture<V extends @Nullable Object>
- Overrides:
get
in classFutureTask<V extends @Nullable Object>
- Throws:
UnsupportedOperationException
- Always
-
-