Class SameThreadScheduledExecutorService
java.lang.Object
java.util.concurrent.AbstractExecutorService
com.google.common.util.concurrent.testing.SameThreadScheduledExecutorService
- All Implemented Interfaces:
ListeningExecutorService
,ListeningScheduledExecutorService
,AutoCloseable
,Executor
,ExecutorService
,ScheduledExecutorService
class SameThreadScheduledExecutorService
extends AbstractExecutorService
implements ListeningScheduledExecutorService
A ScheduledExecutorService that executes all scheduled actions immediately in the calling thread.
See TestingExecutors.sameThreadScheduledExecutor()
for a full list of constraints.
-
Nested Class Summary
Nested ClassesModifier and TypeClassDescriptionprivate static final class
-
Field Summary
Fields -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionboolean
awaitTermination
(long timeout, TimeUnit unit) void
invokeAll
(Collection<? extends Callable<T>> tasks) invokeAll
(Collection<? extends Callable<T>> tasks, long timeout, TimeUnit unit) <T> T
invokeAny
(Collection<? extends Callable<T>> tasks) <T> T
invokeAny
(Collection<? extends Callable<T>> tasks, long timeout, TimeUnit unit) boolean
boolean
<V> ListenableScheduledFuture
<V> scheduleAtFixedRate
(Runnable command, long initialDelay, long period, TimeUnit unit) scheduleWithFixedDelay
(Runnable command, long initialDelay, long delay, TimeUnit unit) void
shutdown()
<T> ListenableFuture
<T> <T> ListenableFuture
<T> Methods inherited from class java.util.concurrent.AbstractExecutorService
newTaskFor, newTaskFor
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
Methods inherited from interface java.util.concurrent.ExecutorService
close
Methods inherited from interface com.google.common.util.concurrent.ListeningExecutorService
awaitTermination, invokeAll, invokeAny
Methods inherited from interface com.google.common.util.concurrent.ListeningScheduledExecutorService
schedule, schedule, scheduleAtFixedRate, scheduleWithFixedDelay
-
Field Details
-
delegate
-
-
Constructor Details
-
SameThreadScheduledExecutorService
SameThreadScheduledExecutorService()
-
-
Method Details
-
shutdown
public void shutdown()- Specified by:
shutdown
in interfaceExecutorService
-
shutdownNow
- Specified by:
shutdownNow
in interfaceExecutorService
-
isShutdown
public boolean isShutdown()- Specified by:
isShutdown
in interfaceExecutorService
-
isTerminated
public boolean isTerminated()- Specified by:
isTerminated
in interfaceExecutorService
-
awaitTermination
- Specified by:
awaitTermination
in interfaceExecutorService
- Throws:
InterruptedException
-
submit
- Specified by:
submit
in interfaceExecutorService
- Specified by:
submit
in interfaceListeningExecutorService
- Overrides:
submit
in classAbstractExecutorService
- Returns:
- a
ListenableFuture
representing pending completion of the task
-
submit
- Specified by:
submit
in interfaceExecutorService
- Specified by:
submit
in interfaceListeningExecutorService
- Overrides:
submit
in classAbstractExecutorService
- Returns:
- a
ListenableFuture
representing pending completion of the task
-
submit
- Specified by:
submit
in interfaceExecutorService
- Specified by:
submit
in interfaceListeningExecutorService
- Overrides:
submit
in classAbstractExecutorService
- Returns:
- a
ListenableFuture
representing pending completion of the task
-
invokeAll
public <T> List<Future<T>> invokeAll(Collection<? extends Callable<T>> tasks) throws InterruptedException Description copied from interface:ListeningExecutorService
All elements in the returned list must be
ListenableFuture
instances. The easiest way to obtain aList<ListenableFuture<T>>
from this method is an unchecked (but safe) cast:@SuppressWarnings("unchecked") // guaranteed by invokeAll contract
List<ListenableFuture<T>> futures = (List) executor.invokeAll(tasks);
- Specified by:
invokeAll
in interfaceExecutorService
- Specified by:
invokeAll
in interfaceListeningExecutorService
- Overrides:
invokeAll
in classAbstractExecutorService
- Returns:
- A list of
ListenableFuture
instances representing the tasks, in the same sequential order as produced by the iterator for the given task list, each of which has completed. - Throws:
InterruptedException
-
invokeAll
public <T> List<Future<T>> invokeAll(Collection<? extends Callable<T>> tasks, long timeout, TimeUnit unit) throws InterruptedException Description copied from interface:ListeningExecutorService
All elements in the returned list must be
ListenableFuture
instances. The easiest way to obtain aList<ListenableFuture<T>>
from this method is an unchecked (but safe) cast:@SuppressWarnings("unchecked") // guaranteed by invokeAll contract
List<ListenableFuture<T>> futures = (List) executor.invokeAll(tasks, timeout, unit);
- Specified by:
invokeAll
in interfaceExecutorService
- Specified by:
invokeAll
in interfaceListeningExecutorService
- Overrides:
invokeAll
in classAbstractExecutorService
- Returns:
- a list of
ListenableFuture
instances representing the tasks, in the same sequential order as produced by the iterator for the given task list. If the operation did not time out, each task will have completed. If it did time out, some of these tasks will not have completed. - Throws:
InterruptedException
-
invokeAny
public <T> T invokeAny(Collection<? extends Callable<T>> tasks) throws InterruptedException, ExecutionException - Specified by:
invokeAny
in interfaceExecutorService
- Overrides:
invokeAny
in classAbstractExecutorService
- Throws:
InterruptedException
ExecutionException
-
invokeAny
public <T> T invokeAny(Collection<? extends Callable<T>> tasks, long timeout, TimeUnit unit) throws InterruptedException, ExecutionException, TimeoutException - Specified by:
invokeAny
in interfaceExecutorService
- Overrides:
invokeAny
in classAbstractExecutorService
- Throws:
InterruptedException
ExecutionException
TimeoutException
-
execute
-
schedule
- Specified by:
schedule
in interfaceListeningScheduledExecutorService
- Specified by:
schedule
in interfaceScheduledExecutorService
-
schedule
- Specified by:
schedule
in interfaceListeningScheduledExecutorService
- Specified by:
schedule
in interfaceScheduledExecutorService
-
scheduleAtFixedRate
public ListenableScheduledFuture<?> scheduleAtFixedRate(Runnable command, long initialDelay, long period, TimeUnit unit) - Specified by:
scheduleAtFixedRate
in interfaceListeningScheduledExecutorService
- Specified by:
scheduleAtFixedRate
in interfaceScheduledExecutorService
-
scheduleWithFixedDelay
public ListenableScheduledFuture<?> scheduleWithFixedDelay(Runnable command, long initialDelay, long delay, TimeUnit unit) - Specified by:
scheduleWithFixedDelay
in interfaceListeningScheduledExecutorService
- Specified by:
scheduleWithFixedDelay
in interfaceScheduledExecutorService
-