public class ScheduledSingleThreadExecutor
extends java.util.concurrent.AbstractExecutorService
implements java.util.concurrent.ScheduledExecutorService
ScheduledThreadPoolExecutor, with the following characteristics:
1. It uses a single worker thread, so it should only execute very brief tasks.
| Constructor and Description |
|---|
ScheduledSingleThreadExecutor() |
ScheduledSingleThreadExecutor(java.util.concurrent.ThreadFactory threadFactory) |
| Modifier and Type | Method and Description |
|---|---|
boolean |
awaitTermination(long timeout,
java.util.concurrent.TimeUnit unit) |
protected <V> java.util.concurrent.RunnableScheduledFuture<V> |
decorateTask(java.util.concurrent.Callable<V> callable,
java.util.concurrent.RunnableScheduledFuture<V> task)
Modifies or replaces the task used to execute a callable.
|
protected <V> java.util.concurrent.RunnableScheduledFuture<V> |
decorateTask(java.lang.Runnable runnable,
java.util.concurrent.RunnableScheduledFuture<V> task)
Modifies or replaces the task used to execute a runnable.
|
void |
execute(java.lang.Runnable command)
Executes
command with zero required delay. |
int |
getActiveCount()
Returns the approximate number of threads that are actively
executing tasks.
|
boolean |
getContinueExistingPeriodicTasksAfterShutdownPolicy()
Gets the policy on whether to continue executing existing
periodic tasks even when this executor has been
shutdown. |
boolean |
getExecuteExistingDelayedTasksAfterShutdownPolicy()
Gets the policy on whether to execute existing delayed
tasks even when this executor has been
shutdown. |
int |
getPoolSize()
Returns the current number of threads in the pool.
|
boolean |
getRemoveOnCancelPolicy()
Gets the policy on whether cancelled tasks should be immediately
removed from the work queue at time of cancellation.
|
boolean |
isShutdown() |
boolean |
isTerminated() |
protected void |
reject(java.lang.Runnable command) |
<V> java.util.concurrent.ScheduledFuture<V> |
schedule(java.util.concurrent.Callable<V> callable,
long delay,
java.util.concurrent.TimeUnit unit) |
java.util.concurrent.ScheduledFuture<?> |
schedule(java.lang.Runnable command,
long delay,
java.util.concurrent.TimeUnit unit) |
java.util.concurrent.ScheduledFuture<?> |
scheduleAtFixedRate(java.lang.Runnable command,
long initialDelay,
long period,
java.util.concurrent.TimeUnit unit) |
java.util.concurrent.ScheduledFuture<?> |
scheduleWithFixedDelay(java.lang.Runnable command,
long initialDelay,
long delay,
java.util.concurrent.TimeUnit unit) |
void |
setContinueExistingPeriodicTasksAfterShutdownPolicy(boolean value)
Sets the policy on whether to continue executing existing
periodic tasks even when this executor has been
shutdown. |
void |
setExecuteExistingDelayedTasksAfterShutdownPolicy(boolean value)
Sets the policy on whether to execute existing delayed
tasks even when this executor has been
shutdown. |
void |
setRemoveOnCancelPolicy(boolean value)
Sets the policy on whether cancelled tasks should be immediately
removed from the work queue at time of cancellation.
|
void |
shutdown()
Initiates an orderly shutdown in which previously submitted
tasks are executed, but no new tasks will be accepted.
|
java.util.List<java.lang.Runnable> |
shutdownNow()
Attempts to stop all actively executing tasks, halts the
processing of waiting tasks, and returns a list of the tasks
that were awaiting execution.
|
<T> java.util.concurrent.Future<T> |
submit(java.util.concurrent.Callable<T> task) |
java.util.concurrent.Future<?> |
submit(java.lang.Runnable task) |
<T> java.util.concurrent.Future<T> |
submit(java.lang.Runnable task,
T result) |
invokeAll, invokeAll, invokeAny, invokeAny, newTaskFor, newTaskForpublic ScheduledSingleThreadExecutor(java.util.concurrent.ThreadFactory threadFactory)
public ScheduledSingleThreadExecutor()
protected void reject(java.lang.Runnable command)
protected <V> java.util.concurrent.RunnableScheduledFuture<V> decorateTask(java.lang.Runnable runnable,
java.util.concurrent.RunnableScheduledFuture<V> task)
runnable - the submitted Runnabletask - the task created to execute the runnableprotected <V> java.util.concurrent.RunnableScheduledFuture<V> decorateTask(java.util.concurrent.Callable<V> callable,
java.util.concurrent.RunnableScheduledFuture<V> task)
callable - the submitted Callabletask - the task created to execute the callablepublic java.util.concurrent.ScheduledFuture<?> schedule(java.lang.Runnable command,
long delay,
java.util.concurrent.TimeUnit unit)
schedule in interface java.util.concurrent.ScheduledExecutorServicejava.util.concurrent.RejectedExecutionExceptionjava.lang.NullPointerExceptionpublic <V> java.util.concurrent.ScheduledFuture<V> schedule(java.util.concurrent.Callable<V> callable,
long delay,
java.util.concurrent.TimeUnit unit)
schedule in interface java.util.concurrent.ScheduledExecutorServicejava.util.concurrent.RejectedExecutionExceptionjava.lang.NullPointerExceptionpublic java.util.concurrent.ScheduledFuture<?> scheduleAtFixedRate(java.lang.Runnable command,
long initialDelay,
long period,
java.util.concurrent.TimeUnit unit)
scheduleAtFixedRate in interface java.util.concurrent.ScheduledExecutorServicejava.util.concurrent.RejectedExecutionExceptionjava.lang.NullPointerExceptionjava.lang.IllegalArgumentExceptionpublic java.util.concurrent.ScheduledFuture<?> scheduleWithFixedDelay(java.lang.Runnable command,
long initialDelay,
long delay,
java.util.concurrent.TimeUnit unit)
scheduleWithFixedDelay in interface java.util.concurrent.ScheduledExecutorServicejava.util.concurrent.RejectedExecutionExceptionjava.lang.NullPointerExceptionjava.lang.IllegalArgumentExceptionpublic void execute(java.lang.Runnable command)
command with zero required delay.
This has effect equivalent to
schedule(command, 0, anyUnit).
Note that inspections of the queue and of the list returned by
shutdownNow will access the zero-delayed
ScheduledFuture, not the command itself.
A consequence of the use of ScheduledFuture objects is
that afterExecute is always
called with a null second Throwable argument, even if the
command terminated abruptly. Instead, the Throwable
thrown by such a task can be obtained via Future.get().
execute in interface java.util.concurrent.Executorjava.util.concurrent.RejectedExecutionException - at discretion of
RejectedExecutionHandler, if the task
cannot be accepted for execution because the
executor has been shut downjava.lang.NullPointerExceptionpublic java.util.concurrent.Future<?> submit(java.lang.Runnable task)
submit in interface java.util.concurrent.ExecutorServicesubmit in class java.util.concurrent.AbstractExecutorServicejava.util.concurrent.RejectedExecutionExceptionjava.lang.NullPointerExceptionpublic <T> java.util.concurrent.Future<T> submit(java.lang.Runnable task,
T result)
submit in interface java.util.concurrent.ExecutorServicesubmit in class java.util.concurrent.AbstractExecutorServicejava.util.concurrent.RejectedExecutionExceptionjava.lang.NullPointerExceptionpublic <T> java.util.concurrent.Future<T> submit(java.util.concurrent.Callable<T> task)
submit in interface java.util.concurrent.ExecutorServicesubmit in class java.util.concurrent.AbstractExecutorServicejava.util.concurrent.RejectedExecutionExceptionjava.lang.NullPointerExceptionpublic void setContinueExistingPeriodicTasksAfterShutdownPolicy(boolean value)
shutdown.
In this case, these tasks will only terminate upon
shutdownNow or after setting the policy to
false when already shutdown.
This value is by default false.value - if true, continue after shutdown, else don'tgetContinueExistingPeriodicTasksAfterShutdownPolicy()public boolean getContinueExistingPeriodicTasksAfterShutdownPolicy()
shutdown.
In this case, these tasks will only terminate upon
shutdownNow or after setting the policy to
false when already shutdown.
This value is by default false.true if will continue after shutdownsetContinueExistingPeriodicTasksAfterShutdownPolicy(boolean)public void setExecuteExistingDelayedTasksAfterShutdownPolicy(boolean value)
shutdown.
In this case, these tasks will only terminate upon
shutdownNow, or after setting the policy to
false when already shutdown.
This value is by default true.value - if true, execute after shutdown, else don'tgetExecuteExistingDelayedTasksAfterShutdownPolicy()public boolean getExecuteExistingDelayedTasksAfterShutdownPolicy()
shutdown.
In this case, these tasks will only terminate upon
shutdownNow, or after setting the policy to
false when already shutdown.
This value is by default true.true if will execute after shutdownsetExecuteExistingDelayedTasksAfterShutdownPolicy(boolean)public void setRemoveOnCancelPolicy(boolean value)
false.value - if true, remove on cancellation, else don'tgetRemoveOnCancelPolicy()public boolean getRemoveOnCancelPolicy()
false.true if cancelled tasks are immediately removed
from the queuesetRemoveOnCancelPolicy(boolean)public void shutdown()
This method does not wait for previously submitted tasks to
complete execution. Use awaitTermination
to do that.
If the ExecuteExistingDelayedTasksAfterShutdownPolicy
has been set false, existing delayed tasks whose delays
have not yet elapsed are cancelled. And unless the ContinueExistingPeriodicTasksAfterShutdownPolicy has been set
true, future executions of existing periodic tasks will
be cancelled.
shutdown in interface java.util.concurrent.ExecutorServicejava.lang.SecurityExceptionpublic java.util.List<java.lang.Runnable> shutdownNow()
This method does not wait for actively executing tasks to
terminate. Use awaitTermination to
do that.
There are no guarantees beyond best-effort attempts to stop
processing actively executing tasks. This implementation
cancels tasks via Thread.interrupt(), so any task that
fails to respond to interrupts may never terminate.
shutdownNow in interface java.util.concurrent.ExecutorServiceScheduledFuture,
including those tasks submitted using execute,
which are for scheduling purposes used as the basis of a
zero-delay ScheduledFuture.java.lang.SecurityExceptionpublic boolean awaitTermination(long timeout,
java.util.concurrent.TimeUnit unit)
throws java.lang.InterruptedException
awaitTermination in interface java.util.concurrent.ExecutorServicejava.lang.InterruptedExceptionpublic boolean isShutdown()
isShutdown in interface java.util.concurrent.ExecutorServicepublic boolean isTerminated()
isTerminated in interface java.util.concurrent.ExecutorServicepublic int getPoolSize()
public int getActiveCount()