@GwtIncompatible
public final class LazyExecutorService
extends java.lang.Object
implements java.util.concurrent.ExecutorService
In essence, a returned Future represents a "canned" method call and once the call has been performed, the Future returns the cached result.
Both this class and the returned Future are thread-safe.
Constructor and Description |
---|
LazyExecutorService()
Creates an instance using a
MoreExecutors.newDirectExecutorService() for the backing
service. |
LazyExecutorService(java.util.concurrent.ExecutorService backingService)
Creates an instance using the given
ExecutorService as the backing service. |
Modifier and Type | Method and Description |
---|---|
boolean |
awaitTermination(long timeout,
java.util.concurrent.TimeUnit unit) |
void |
execute(java.lang.Runnable command)
Always throws a RejectedExecutionException because using this method does not make sense from
either a lazy execution perspective or a cached result perspective.
|
<T> java.util.List<java.util.concurrent.Future<T>> |
invokeAll(java.util.Collection<? extends java.util.concurrent.Callable<T>> tasks)
ExecutorService requires that this method should not return until all tasks are completed,
which precludes lazy execution.
|
<T> java.util.List<java.util.concurrent.Future<T>> |
invokeAll(java.util.Collection<? extends java.util.concurrent.Callable<T>> tasks,
long timeout,
java.util.concurrent.TimeUnit unit)
ExecutorService requires that this method should not return until all tasks are completed or
the timeout expires, which precludes lazy execution.
|
<T> T |
invokeAny(java.util.Collection<? extends java.util.concurrent.Callable<T>> tasks)
Always throws a RejectedExecutionException because using this method does not make sense from
either a lazy execution perspective or a cached result perspective.
|
<T> T |
invokeAny(java.util.Collection<? extends java.util.concurrent.Callable<T>> tasks,
long timeout,
java.util.concurrent.TimeUnit unit)
Always throws a RejectedExecutionException because using this method does not make sense from
either a lazy execution perspective or a cached result perspective.
|
boolean |
isShutdown() |
boolean |
isTerminated() |
void |
shutdown()
Shuts this service down, but leaves the backing service untouched.
|
java.util.List<java.lang.Runnable> |
shutdownNow()
Trying to interpret the assumptions about the contract of this method in the light of this
implementation, it seems most reasonable to take the view that all tasks are running, even if
the processing has not actually started.
|
<T> java.util.concurrent.Future<T> |
submit(java.util.concurrent.Callable<T> task) |
java.util.concurrent.Future<?> |
submit(java.lang.Runnable command) |
<T> java.util.concurrent.Future<T> |
submit(java.lang.Runnable task,
T result) |
public LazyExecutorService()
MoreExecutors.newDirectExecutorService()
for the backing
service.public LazyExecutorService(java.util.concurrent.ExecutorService backingService)
ExecutorService
as the backing service.
The backing service will only be used to execute tasks and it may be shared by several instances or used for other purposes. Shutdowns of this instance will not shut down the backing service.
If you shut down the backing service, this instance will be shut down automatically and all tasks submitted to this instance that have not yet been submitted to the backing service will be considered cancelled.
public void shutdown()
shutdown
in interface java.util.concurrent.ExecutorService
@CanIgnoreReturnValue public java.util.List<java.lang.Runnable> shutdownNow()
shutdownNow
in interface java.util.concurrent.ExecutorService
public boolean isShutdown()
isShutdown
in interface java.util.concurrent.ExecutorService
public boolean isTerminated()
isTerminated
in interface java.util.concurrent.ExecutorService
public boolean awaitTermination(long timeout, java.util.concurrent.TimeUnit unit) throws java.lang.InterruptedException
awaitTermination
in interface java.util.concurrent.ExecutorService
java.lang.InterruptedException
public <T> java.util.concurrent.Future<T> submit(java.util.concurrent.Callable<T> task)
submit
in interface java.util.concurrent.ExecutorService
public <T> java.util.concurrent.Future<T> submit(java.lang.Runnable task, T result)
submit
in interface java.util.concurrent.ExecutorService
public java.util.concurrent.Future<?> submit(java.lang.Runnable command)
submit
in interface java.util.concurrent.ExecutorService
@CanIgnoreReturnValue public <T> java.util.List<java.util.concurrent.Future<T>> invokeAll(java.util.Collection<? extends java.util.concurrent.Callable<T>> tasks) throws java.lang.InterruptedException
This method makes sense from a cached result perspective but not from a lazy execution perspective.
invokeAll
in interface java.util.concurrent.ExecutorService
java.lang.InterruptedException
@CanIgnoreReturnValue public <T> java.util.List<java.util.concurrent.Future<T>> invokeAll(java.util.Collection<? extends java.util.concurrent.Callable<T>> tasks, long timeout, java.util.concurrent.TimeUnit unit) throws java.lang.InterruptedException
This method makes sense from a cached result perspective but not from a lazy execution perspective.
invokeAll
in interface java.util.concurrent.ExecutorService
java.lang.InterruptedException
public <T> T invokeAny(java.util.Collection<? extends java.util.concurrent.Callable<T>> tasks)
invokeAny
in interface java.util.concurrent.ExecutorService
public <T> T invokeAny(java.util.Collection<? extends java.util.concurrent.Callable<T>> tasks, long timeout, java.util.concurrent.TimeUnit unit)
invokeAny
in interface java.util.concurrent.ExecutorService
public void execute(java.lang.Runnable command)
execute
in interface java.util.concurrent.Executor
Copyright © 2019. All rights reserved.