Class SameThreadScheduledExecutorService
- java.lang.Object
-
- java.util.concurrent.AbstractExecutorService
-
- com.google.common.util.concurrent.testing.SameThreadScheduledExecutorService
-
- All Implemented Interfaces:
ListeningExecutorService
,ListeningScheduledExecutorService
,java.util.concurrent.Executor
,java.util.concurrent.ExecutorService
,java.util.concurrent.ScheduledExecutorService
class SameThreadScheduledExecutorService extends java.util.concurrent.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 Classes Modifier and Type Class Description private static class
SameThreadScheduledExecutorService.ImmediateScheduledFuture<V>
-
Field Summary
Fields Modifier and Type Field Description private ListeningExecutorService
delegate
-
Constructor Summary
Constructors Constructor Description SameThreadScheduledExecutorService()
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description boolean
awaitTermination(long timeout, java.util.concurrent.TimeUnit unit)
void
execute(java.lang.Runnable command)
<T> java.util.List<java.util.concurrent.Future<T>>
invokeAll(java.util.Collection<? extends java.util.concurrent.Callable<T>> tasks)
<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)
<T> T
invokeAny(java.util.Collection<? extends java.util.concurrent.Callable<T>> tasks)
<T> T
invokeAny(java.util.Collection<? extends java.util.concurrent.Callable<T>> tasks, long timeout, java.util.concurrent.TimeUnit unit)
boolean
isShutdown()
boolean
isTerminated()
ListenableScheduledFuture<?>
schedule(java.lang.Runnable command, long delay, java.util.concurrent.TimeUnit unit)
<V> ListenableScheduledFuture<V>
schedule(java.util.concurrent.Callable<V> callable, long delay, java.util.concurrent.TimeUnit unit)
ListenableScheduledFuture<?>
scheduleAtFixedRate(java.lang.Runnable command, long initialDelay, long period, java.util.concurrent.TimeUnit unit)
ListenableScheduledFuture<?>
scheduleWithFixedDelay(java.lang.Runnable command, long initialDelay, long delay, java.util.concurrent.TimeUnit unit)
void
shutdown()
java.util.List<java.lang.Runnable>
shutdownNow()
ListenableFuture<?>
submit(java.lang.Runnable task)
<T> ListenableFuture<T>
submit(java.lang.Runnable task, T result)
<T> ListenableFuture<T>
submit(java.util.concurrent.Callable<T> task)
-
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
-
Methods inherited from interface com.google.common.util.concurrent.ListeningScheduledExecutorService
schedule, schedule, scheduleAtFixedRate, scheduleWithFixedDelay
-
-
-
-
Field Detail
-
delegate
private final ListeningExecutorService delegate
-
-
Method Detail
-
shutdown
public void shutdown()
- Specified by:
shutdown
in interfacejava.util.concurrent.ExecutorService
-
shutdownNow
public java.util.List<java.lang.Runnable> shutdownNow()
- Specified by:
shutdownNow
in interfacejava.util.concurrent.ExecutorService
-
isShutdown
public boolean isShutdown()
- Specified by:
isShutdown
in interfacejava.util.concurrent.ExecutorService
-
isTerminated
public boolean isTerminated()
- Specified by:
isTerminated
in interfacejava.util.concurrent.ExecutorService
-
awaitTermination
public boolean awaitTermination(long timeout, java.util.concurrent.TimeUnit unit) throws java.lang.InterruptedException
- Specified by:
awaitTermination
in interfacejava.util.concurrent.ExecutorService
- Throws:
java.lang.InterruptedException
-
submit
public <T> ListenableFuture<T> submit(java.util.concurrent.Callable<T> task)
- Specified by:
submit
in interfacejava.util.concurrent.ExecutorService
- Specified by:
submit
in interfaceListeningExecutorService
- Overrides:
submit
in classjava.util.concurrent.AbstractExecutorService
- Returns:
- a
ListenableFuture
representing pending completion of the task
-
submit
public <T> ListenableFuture<T> submit(java.lang.Runnable task, T result)
- Specified by:
submit
in interfacejava.util.concurrent.ExecutorService
- Specified by:
submit
in interfaceListeningExecutorService
- Overrides:
submit
in classjava.util.concurrent.AbstractExecutorService
- Returns:
- a
ListenableFuture
representing pending completion of the task
-
submit
public ListenableFuture<?> submit(java.lang.Runnable task)
- Specified by:
submit
in interfacejava.util.concurrent.ExecutorService
- Specified by:
submit
in interfaceListeningExecutorService
- Overrides:
submit
in classjava.util.concurrent.AbstractExecutorService
- Returns:
- a
ListenableFuture
representing pending completion of the task
-
invokeAll
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
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 interfacejava.util.concurrent.ExecutorService
- Specified by:
invokeAll
in interfaceListeningExecutorService
- Overrides:
invokeAll
in classjava.util.concurrent.AbstractExecutorService
- 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:
java.lang.InterruptedException
-
invokeAll
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
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 interfacejava.util.concurrent.ExecutorService
- Specified by:
invokeAll
in interfaceListeningExecutorService
- Overrides:
invokeAll
in classjava.util.concurrent.AbstractExecutorService
- 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:
java.lang.InterruptedException
-
invokeAny
public <T> T invokeAny(java.util.Collection<? extends java.util.concurrent.Callable<T>> tasks) throws java.lang.InterruptedException, java.util.concurrent.ExecutionException
- Specified by:
invokeAny
in interfacejava.util.concurrent.ExecutorService
- Overrides:
invokeAny
in classjava.util.concurrent.AbstractExecutorService
- Throws:
java.lang.InterruptedException
java.util.concurrent.ExecutionException
-
invokeAny
public <T> T invokeAny(java.util.Collection<? extends java.util.concurrent.Callable<T>> tasks, long timeout, java.util.concurrent.TimeUnit unit) throws java.lang.InterruptedException, java.util.concurrent.ExecutionException, java.util.concurrent.TimeoutException
- Specified by:
invokeAny
in interfacejava.util.concurrent.ExecutorService
- Overrides:
invokeAny
in classjava.util.concurrent.AbstractExecutorService
- Throws:
java.lang.InterruptedException
java.util.concurrent.ExecutionException
java.util.concurrent.TimeoutException
-
execute
public void execute(java.lang.Runnable command)
- Specified by:
execute
in interfacejava.util.concurrent.Executor
-
schedule
public ListenableScheduledFuture<?> schedule(java.lang.Runnable command, long delay, java.util.concurrent.TimeUnit unit)
- Specified by:
schedule
in interfaceListeningScheduledExecutorService
- Specified by:
schedule
in interfacejava.util.concurrent.ScheduledExecutorService
-
schedule
public <V> ListenableScheduledFuture<V> schedule(java.util.concurrent.Callable<V> callable, long delay, java.util.concurrent.TimeUnit unit)
- Specified by:
schedule
in interfaceListeningScheduledExecutorService
- Specified by:
schedule
in interfacejava.util.concurrent.ScheduledExecutorService
-
scheduleAtFixedRate
public ListenableScheduledFuture<?> scheduleAtFixedRate(java.lang.Runnable command, long initialDelay, long period, java.util.concurrent.TimeUnit unit)
- Specified by:
scheduleAtFixedRate
in interfaceListeningScheduledExecutorService
- Specified by:
scheduleAtFixedRate
in interfacejava.util.concurrent.ScheduledExecutorService
-
scheduleWithFixedDelay
public ListenableScheduledFuture<?> scheduleWithFixedDelay(java.lang.Runnable command, long initialDelay, long delay, java.util.concurrent.TimeUnit unit)
- Specified by:
scheduleWithFixedDelay
in interfaceListeningScheduledExecutorService
- Specified by:
scheduleWithFixedDelay
in interfacejava.util.concurrent.ScheduledExecutorService
-
-