Added in [API level 1](https://developer.android.com/guide/topics/manifest/uses-sdk-element#ApiLevels) Summary: [Ctors](https://developer.android.com/reference/java/util/concurrent/ScheduledThreadPoolExecutor#pubctors) \| [Methods](https://developer.android.com/reference/java/util/concurrent/ScheduledThreadPoolExecutor#pubmethods) \| [Protected Methods](https://developer.android.com/reference/java/util/concurrent/ScheduledThreadPoolExecutor#promethods) \| [Inherited Methods](https://developer.android.com/reference/java/util/concurrent/ScheduledThreadPoolExecutor#inhmethods)

# ScheduledThreadPoolExecutor


`
public


class
ScheduledThreadPoolExecutor
`


`


`

`


`

`

extends https://developer.android.com/reference/java/util/concurrent/ThreadPoolExecutor


`

`


implements

https://developer.android.com/reference/java/util/concurrent/ScheduledExecutorService


`

|---|---|---|---|
| [java.lang.Object](https://developer.android.com/reference/java/lang/Object) ||||
| ↳ | [java.util.concurrent.AbstractExecutorService](https://developer.android.com/reference/java/util/concurrent/AbstractExecutorService) |||
|   | ↳ | [java.util.concurrent.ThreadPoolExecutor](https://developer.android.com/reference/java/util/concurrent/ThreadPoolExecutor) ||
|   |   | ↳ | java.util.concurrent.ScheduledThreadPoolExecutor |

<br />

*** ** * ** ***

A `https://developer.android.com/reference/java/util/concurrent/ThreadPoolExecutor` that can additionally schedule
commands to run after a given delay, or to execute periodically.
This class is preferable to `https://developer.android.com/reference/java/util/Timer` when multiple
worker threads are needed, or when the additional flexibility or
capabilities of `https://developer.android.com/reference/java/util/concurrent/ThreadPoolExecutor` (which this class
extends) are required.

Delayed tasks execute no sooner than they are enabled, but
without any real-time guarantees about when, after they are
enabled, they will commence. Tasks scheduled for exactly the same
execution time are enabled in first-in-first-out (FIFO) order of
submission.

When a submitted task is cancelled before it is run, execution
is suppressed. By default, such a cancelled task is not
automatically removed from the work queue until its delay elapses.
While this enables further inspection and monitoring, it may also
cause unbounded retention of cancelled tasks.

Successive executions of a periodic task scheduled via
`https://developer.android.com/reference/java/util/concurrent/ScheduledThreadPoolExecutor#scheduleAtFixedRate(java.lang.Runnable,%20long,%20long,%20java.util.concurrent.TimeUnit)` or
`https://developer.android.com/reference/java/util/concurrent/ScheduledThreadPoolExecutor#scheduleWithFixedDelay(java.lang.Runnable,%20long,%20long,%20java.util.concurrent.TimeUnit)`
do not overlap. While different executions may be performed by
different threads, the effects of prior executions
[*happen-before*](https://developer.android.com/reference/java/util/concurrent/package-summary#MemoryVisibility)
those of subsequent ones.

While this class inherits from `https://developer.android.com/reference/java/util/concurrent/ThreadPoolExecutor`, a few
of the inherited tuning methods are not useful for it. In
particular, because it acts as a fixed-sized pool using
`corePoolSize` threads and an unbounded queue, adjustments
to `maximumPoolSize` have no useful effect. Additionally, it
is almost never a good idea to set `corePoolSize` to zero or
use `allowCoreThreadTimeOut` because this may leave the pool
without threads to handle tasks once they become eligible to run.

As with `ThreadPoolExecutor`, if not otherwise specified,
this class uses `https://developer.android.com/reference/java/util/concurrent/Executors#defaultThreadFactory()` as the
default thread factory, and `https://developer.android.com/reference/java/util/concurrent/ThreadPoolExecutor.AbortPolicy`
as the default rejected execution handler.

**Extension notes:** This class overrides the
`https://developer.android.com/reference/java/util/concurrent/ThreadPoolExecutor#execute(java.lang.Runnable)` and
`https://developer.android.com/reference/java/util/concurrent/AbstractExecutorService#submit(java.lang.Runnable)`
methods to generate internal `https://developer.android.com/reference/java/util/concurrent/ScheduledFuture` objects to
control per-task delays and scheduling. To preserve
functionality, any further overrides of these methods in
subclasses must invoke superclass versions, which effectively
disables additional task customization. However, this class
provides alternative protected extension method
`decorateTask` (one version each for `Runnable` and
`Callable`) that can be used to customize the concrete task
types used to execute commands entered via `execute`,
`submit`, `schedule`, `scheduleAtFixedRate`,
and `scheduleWithFixedDelay`. By default, a
`ScheduledThreadPoolExecutor` uses a task type extending
`https://developer.android.com/reference/java/util/concurrent/FutureTask`. However, this may be modified or replaced using
subclasses of the form:

     public class CustomScheduledExecutor extends ScheduledThreadPoolExecutor {

       static class CustomTask<V> implements RunnableScheduledFuture<V> { ... }

       protected <V> RunnableScheduledFuture<V> decorateTask(
                    Runnable r, RunnableScheduledFuture<V> task) {
           return new CustomTask<V>(r, task);
       }

       protected <V> RunnableScheduledFuture<V> decorateTask(
                    Callable<V> c, RunnableScheduledFuture<V> task) {
           return new CustomTask<V>(c, task);
       }
       // ... add constructors, etc.
     }

<br />

## Summary

| ### Public constructors ||
|---|---|
| ` https://developer.android.com/reference/java/util/concurrent/ScheduledThreadPoolExecutor#ScheduledThreadPoolExecutor(int)(int corePoolSize) ` Creates a new `ScheduledThreadPoolExecutor` with the given core pool size. |
| ` https://developer.android.com/reference/java/util/concurrent/ScheduledThreadPoolExecutor#ScheduledThreadPoolExecutor(int,%20java.util.concurrent.RejectedExecutionHandler)(int corePoolSize, https://developer.android.com/reference/java/util/concurrent/RejectedExecutionHandler handler) ` Creates a new `ScheduledThreadPoolExecutor` with the given initial parameters. |
| ` https://developer.android.com/reference/java/util/concurrent/ScheduledThreadPoolExecutor#ScheduledThreadPoolExecutor(int,%20java.util.concurrent.ThreadFactory)(int corePoolSize, https://developer.android.com/reference/java/util/concurrent/ThreadFactory threadFactory) ` Creates a new `ScheduledThreadPoolExecutor` with the given initial parameters. |
| ` https://developer.android.com/reference/java/util/concurrent/ScheduledThreadPoolExecutor#ScheduledThreadPoolExecutor(int,%20java.util.concurrent.ThreadFactory,%20java.util.concurrent.RejectedExecutionHandler)(int corePoolSize, https://developer.android.com/reference/java/util/concurrent/ThreadFactory threadFactory, https://developer.android.com/reference/java/util/concurrent/RejectedExecutionHandler handler) ` Creates a new `ScheduledThreadPoolExecutor` with the given initial parameters. |

| ### Public methods ||
|---|---|
| ` void` | ` https://developer.android.com/reference/java/util/concurrent/ScheduledThreadPoolExecutor#execute(java.lang.Runnable)(https://developer.android.com/reference/java/lang/Runnable command) ` Executes `command` with zero required delay. |
| ` boolean` | ` https://developer.android.com/reference/java/util/concurrent/ScheduledThreadPoolExecutor#getContinueExistingPeriodicTasksAfterShutdownPolicy()() ` Gets the policy on whether to continue executing existing periodic tasks even when this executor has been `shutdown`. |
| ` boolean` | ` https://developer.android.com/reference/java/util/concurrent/ScheduledThreadPoolExecutor#getExecuteExistingDelayedTasksAfterShutdownPolicy()() ` Gets the policy on whether to execute existing delayed tasks even when this executor has been `shutdown`. |
| ` https://developer.android.com/reference/java/util/concurrent/BlockingQueue<https://developer.android.com/reference/java/lang/Runnable>` | ` https://developer.android.com/reference/java/util/concurrent/ScheduledThreadPoolExecutor#getQueue()() ` Returns the task queue used by this executor. |
| ` boolean` | ` https://developer.android.com/reference/java/util/concurrent/ScheduledThreadPoolExecutor#getRemoveOnCancelPolicy()() ` Gets the policy on whether cancelled tasks should be immediately removed from the work queue at time of cancellation. |
| ` <V> https://developer.android.com/reference/java/util/concurrent/ScheduledFuture<V>` | ` https://developer.android.com/reference/java/util/concurrent/ScheduledThreadPoolExecutor#schedule(java.util.concurrent.Callable<V>,%20long,%20java.util.concurrent.TimeUnit)(https://developer.android.com/reference/java/util/concurrent/Callable<V> callable, long delay, https://developer.android.com/reference/java/util/concurrent/TimeUnit unit) ` Submits a value-returning one-shot task that becomes enabled after the given delay. |
| ` https://developer.android.com/reference/java/util/concurrent/ScheduledFuture<?>` | ` https://developer.android.com/reference/java/util/concurrent/ScheduledThreadPoolExecutor#schedule(java.lang.Runnable,%20long,%20java.util.concurrent.TimeUnit)(https://developer.android.com/reference/java/lang/Runnable command, long delay, https://developer.android.com/reference/java/util/concurrent/TimeUnit unit) ` Submits a one-shot task that becomes enabled after the given delay. |
| ` https://developer.android.com/reference/java/util/concurrent/ScheduledFuture<?>` | ` https://developer.android.com/reference/java/util/concurrent/ScheduledThreadPoolExecutor#scheduleAtFixedRate(java.lang.Runnable,%20long,%20long,%20java.util.concurrent.TimeUnit)(https://developer.android.com/reference/java/lang/Runnable command, long initialDelay, long period, https://developer.android.com/reference/java/util/concurrent/TimeUnit unit) ` Submits a periodic action that becomes enabled first after the given initial delay, and subsequently with the given period; that is, executions will commence after `initialDelay`, then `initialDelay + period`, then `initialDelay + 2 * period`, and so on. |
| ` https://developer.android.com/reference/java/util/concurrent/ScheduledFuture<?>` | ` https://developer.android.com/reference/java/util/concurrent/ScheduledThreadPoolExecutor#scheduleWithFixedDelay(java.lang.Runnable,%20long,%20long,%20java.util.concurrent.TimeUnit)(https://developer.android.com/reference/java/lang/Runnable command, long initialDelay, long delay, https://developer.android.com/reference/java/util/concurrent/TimeUnit unit) ` Submits a periodic action that becomes enabled first after the given initial delay, and subsequently with the given delay between the termination of one execution and the commencement of the next. |
| ` void` | ` https://developer.android.com/reference/java/util/concurrent/ScheduledThreadPoolExecutor#setContinueExistingPeriodicTasksAfterShutdownPolicy(boolean)(boolean value) ` Sets the policy on whether to continue executing existing periodic tasks even when this executor has been `shutdown`. |
| ` void` | ` https://developer.android.com/reference/java/util/concurrent/ScheduledThreadPoolExecutor#setExecuteExistingDelayedTasksAfterShutdownPolicy(boolean)(boolean value) ` Sets the policy on whether to execute existing delayed tasks even when this executor has been `shutdown`. |
| ` void` | ` https://developer.android.com/reference/java/util/concurrent/ScheduledThreadPoolExecutor#setRemoveOnCancelPolicy(boolean)(boolean value) ` Sets the policy on whether cancelled tasks should be immediately removed from the work queue at time of cancellation. |
| ` void` | ` https://developer.android.com/reference/java/util/concurrent/ScheduledThreadPoolExecutor#shutdown()() ` Initiates an orderly shutdown in which previously submitted tasks are executed, but no new tasks will be accepted. |
| ` https://developer.android.com/reference/java/util/List<https://developer.android.com/reference/java/lang/Runnable>` | ` https://developer.android.com/reference/java/util/concurrent/ScheduledThreadPoolExecutor#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. |
| ` https://developer.android.com/reference/java/util/concurrent/Future<?>` | ` https://developer.android.com/reference/java/util/concurrent/ScheduledThreadPoolExecutor#submit(java.lang.Runnable)(https://developer.android.com/reference/java/lang/Runnable task) ` Submits a Runnable task for execution and returns a Future representing that task. |
| ` <T> https://developer.android.com/reference/java/util/concurrent/Future<T>` | ` https://developer.android.com/reference/java/util/concurrent/ScheduledThreadPoolExecutor#submit(java.util.concurrent.Callable<T>)(https://developer.android.com/reference/java/util/concurrent/Callable<T> task) ` Submits a value-returning task for execution and returns a Future representing the pending results of the task. |
| ` <T> https://developer.android.com/reference/java/util/concurrent/Future<T>` | ` https://developer.android.com/reference/java/util/concurrent/ScheduledThreadPoolExecutor#submit(java.lang.Runnable,%20T)(https://developer.android.com/reference/java/lang/Runnable task, T result) ` Submits a Runnable task for execution and returns a Future representing that task. |

| ### Protected methods ||
|---|---|
| ` <V> https://developer.android.com/reference/java/util/concurrent/RunnableScheduledFuture<V>` | ` https://developer.android.com/reference/java/util/concurrent/ScheduledThreadPoolExecutor#decorateTask(java.lang.Runnable,%20java.util.concurrent.RunnableScheduledFuture<V>)(https://developer.android.com/reference/java/lang/Runnable runnable, https://developer.android.com/reference/java/util/concurrent/RunnableScheduledFuture<V> task) ` Modifies or replaces the task used to execute a runnable. |
| ` <V> https://developer.android.com/reference/java/util/concurrent/RunnableScheduledFuture<V>` | ` https://developer.android.com/reference/java/util/concurrent/ScheduledThreadPoolExecutor#decorateTask(java.util.concurrent.Callable<V>,%20java.util.concurrent.RunnableScheduledFuture<V>)(https://developer.android.com/reference/java/util/concurrent/Callable<V> callable, https://developer.android.com/reference/java/util/concurrent/RunnableScheduledFuture<V> task) ` Modifies or replaces the task used to execute a callable. |

| ### Inherited methods |
|---|---|
| From class ` https://developer.android.com/reference/java/util/concurrent/ThreadPoolExecutor ` |---|---| | ` void` | ` https://developer.android.com/reference/java/util/concurrent/ThreadPoolExecutor#afterExecute(java.lang.Runnable,%20java.lang.Throwable)(https://developer.android.com/reference/java/lang/Runnable r, https://developer.android.com/reference/java/lang/Throwable t) ` Method invoked upon completion of execution of the given Runnable. | | ` void` | ` https://developer.android.com/reference/java/util/concurrent/ThreadPoolExecutor#allowCoreThreadTimeOut(boolean)(boolean value) ` Sets the policy governing whether core threads may time out and terminate if no tasks arrive within the keep-alive time, being replaced if needed when new tasks arrive. | | ` boolean` | ` https://developer.android.com/reference/java/util/concurrent/ThreadPoolExecutor#allowsCoreThreadTimeOut()() ` Returns true if this pool allows core threads to time out and terminate if no tasks arrive within the keepAlive time, being replaced if needed when new tasks arrive. | | ` boolean` | ` https://developer.android.com/reference/java/util/concurrent/ThreadPoolExecutor#awaitTermination(long,%20java.util.concurrent.TimeUnit)(long timeout, https://developer.android.com/reference/java/util/concurrent/TimeUnit unit) ` | | ` void` | ` https://developer.android.com/reference/java/util/concurrent/ThreadPoolExecutor#beforeExecute(java.lang.Thread,%20java.lang.Runnable)(https://developer.android.com/reference/java/lang/Thread t, https://developer.android.com/reference/java/lang/Runnable r) ` Method invoked prior to executing the given Runnable in the given thread. | | ` void` | ` https://developer.android.com/reference/java/util/concurrent/ThreadPoolExecutor#execute(java.lang.Runnable)(https://developer.android.com/reference/java/lang/Runnable command) ` Executes the given task sometime in the future. | | ` void` | ` https://developer.android.com/reference/java/util/concurrent/ThreadPoolExecutor#finalize()() ` *This method is deprecated. Subclass is not recommended to override finalize(). If it must, please always invoke super.finalize().* | | ` int` | ` https://developer.android.com/reference/java/util/concurrent/ThreadPoolExecutor#getActiveCount()() ` Returns the approximate number of threads that are actively executing tasks. | | ` long` | ` https://developer.android.com/reference/java/util/concurrent/ThreadPoolExecutor#getCompletedTaskCount()() ` Returns the approximate total number of tasks that have completed execution. | | ` int` | ` https://developer.android.com/reference/java/util/concurrent/ThreadPoolExecutor#getCorePoolSize()() ` Returns the core number of threads. | | ` long` | ` https://developer.android.com/reference/java/util/concurrent/ThreadPoolExecutor#getKeepAliveTime(java.util.concurrent.TimeUnit)(https://developer.android.com/reference/java/util/concurrent/TimeUnit unit) ` Returns the thread keep-alive time, which is the amount of time that threads may remain idle before being terminated. | | ` int` | ` https://developer.android.com/reference/java/util/concurrent/ThreadPoolExecutor#getLargestPoolSize()() ` Returns the largest number of threads that have ever simultaneously been in the pool. | | ` int` | ` https://developer.android.com/reference/java/util/concurrent/ThreadPoolExecutor#getMaximumPoolSize()() ` Returns the maximum allowed number of threads. | | ` int` | ` https://developer.android.com/reference/java/util/concurrent/ThreadPoolExecutor#getPoolSize()() ` Returns the current number of threads in the pool. | | ` https://developer.android.com/reference/java/util/concurrent/BlockingQueue<https://developer.android.com/reference/java/lang/Runnable>` | ` https://developer.android.com/reference/java/util/concurrent/ThreadPoolExecutor#getQueue()() ` Returns the task queue used by this executor. | | ` https://developer.android.com/reference/java/util/concurrent/RejectedExecutionHandler` | ` https://developer.android.com/reference/java/util/concurrent/ThreadPoolExecutor#getRejectedExecutionHandler()() ` Returns the current handler for unexecutable tasks. | | ` long` | ` https://developer.android.com/reference/java/util/concurrent/ThreadPoolExecutor#getTaskCount()() ` Returns the approximate total number of tasks that have ever been scheduled for execution. | | ` https://developer.android.com/reference/java/util/concurrent/ThreadFactory` | ` https://developer.android.com/reference/java/util/concurrent/ThreadPoolExecutor#getThreadFactory()() ` Returns the thread factory used to create new threads. | | ` boolean` | ` https://developer.android.com/reference/java/util/concurrent/ThreadPoolExecutor#isShutdown()() ` | | ` boolean` | ` https://developer.android.com/reference/java/util/concurrent/ThreadPoolExecutor#isTerminated()() ` | | ` boolean` | ` https://developer.android.com/reference/java/util/concurrent/ThreadPoolExecutor#isTerminating()() ` Returns true if this executor is in the process of terminating after `https://developer.android.com/reference/java/util/concurrent/ThreadPoolExecutor#shutdown()` or `https://developer.android.com/reference/java/util/concurrent/ThreadPoolExecutor#shutdownNow()` but has not completely terminated. | | ` int` | ` https://developer.android.com/reference/java/util/concurrent/ThreadPoolExecutor#prestartAllCoreThreads()() ` Starts all core threads, causing them to idly wait for work. | | ` boolean` | ` https://developer.android.com/reference/java/util/concurrent/ThreadPoolExecutor#prestartCoreThread()() ` Starts a core thread, causing it to idly wait for work. | | ` void` | ` https://developer.android.com/reference/java/util/concurrent/ThreadPoolExecutor#purge()() ` Tries to remove from the work queue all `https://developer.android.com/reference/java/util/concurrent/Future` tasks that have been cancelled. | | ` boolean` | ` https://developer.android.com/reference/java/util/concurrent/ThreadPoolExecutor#remove(java.lang.Runnable)(https://developer.android.com/reference/java/lang/Runnable task) ` Removes this task from the executor's internal queue if it is present, thus causing it not to be run if it has not already started. | | ` void` | ` https://developer.android.com/reference/java/util/concurrent/ThreadPoolExecutor#setCorePoolSize(int)(int corePoolSize) ` Sets the core number of threads. | | ` void` | ` https://developer.android.com/reference/java/util/concurrent/ThreadPoolExecutor#setKeepAliveTime(long,%20java.util.concurrent.TimeUnit)(long time, https://developer.android.com/reference/java/util/concurrent/TimeUnit unit) ` Sets the thread keep-alive time, which is the amount of time that threads may remain idle before being terminated. | | ` void` | ` https://developer.android.com/reference/java/util/concurrent/ThreadPoolExecutor#setMaximumPoolSize(int)(int maximumPoolSize) ` Sets the maximum allowed number of threads. | | ` void` | ` https://developer.android.com/reference/java/util/concurrent/ThreadPoolExecutor#setRejectedExecutionHandler(java.util.concurrent.RejectedExecutionHandler)(https://developer.android.com/reference/java/util/concurrent/RejectedExecutionHandler handler) ` Sets a new handler for unexecutable tasks. | | ` void` | ` https://developer.android.com/reference/java/util/concurrent/ThreadPoolExecutor#setThreadFactory(java.util.concurrent.ThreadFactory)(https://developer.android.com/reference/java/util/concurrent/ThreadFactory threadFactory) ` Sets the thread factory used to create new threads. | | ` void` | ` https://developer.android.com/reference/java/util/concurrent/ThreadPoolExecutor#shutdown()() ` Initiates an orderly shutdown in which previously submitted tasks are executed, but no new tasks will be accepted. | | ` https://developer.android.com/reference/java/util/List<https://developer.android.com/reference/java/lang/Runnable>` | ` https://developer.android.com/reference/java/util/concurrent/ThreadPoolExecutor#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. | | ` void` | ` https://developer.android.com/reference/java/util/concurrent/ThreadPoolExecutor#terminated()() ` Method invoked when the Executor has terminated. | | ` https://developer.android.com/reference/java/lang/String` | ` https://developer.android.com/reference/java/util/concurrent/ThreadPoolExecutor#toString()() ` Returns a string identifying this pool, as well as its state, including indications of run state and estimated worker and task counts. | ||
| From class ` https://developer.android.com/reference/java/util/concurrent/AbstractExecutorService ` |---|---| | ` <T> https://developer.android.com/reference/java/util/List<https://developer.android.com/reference/java/util/concurrent/Future<T>>` | ` https://developer.android.com/reference/java/util/concurrent/AbstractExecutorService#invokeAll(java.util.Collection<?%20extends%20java.util.concurrent.Callable<T>>)(https://developer.android.com/reference/java/util/Collection<? extends https://developer.android.com/reference/java/util/concurrent/Callable<T>> tasks) ` Executes the given tasks, returning a list of Futures holding their status and results when all complete. | | ` <T> https://developer.android.com/reference/java/util/List<https://developer.android.com/reference/java/util/concurrent/Future<T>>` | ` https://developer.android.com/reference/java/util/concurrent/AbstractExecutorService#invokeAll(java.util.Collection<?%20extends%20java.util.concurrent.Callable<T>>,%20long,%20java.util.concurrent.TimeUnit)(https://developer.android.com/reference/java/util/Collection<? extends https://developer.android.com/reference/java/util/concurrent/Callable<T>> tasks, long timeout, https://developer.android.com/reference/java/util/concurrent/TimeUnit unit) ` Executes the given tasks, returning a list of Futures holding their status and results when all complete or the timeout expires, whichever happens first. | | ` <T> T` | ` https://developer.android.com/reference/java/util/concurrent/AbstractExecutorService#invokeAny(java.util.Collection<?%20extends%20java.util.concurrent.Callable<T>>)(https://developer.android.com/reference/java/util/Collection<? extends https://developer.android.com/reference/java/util/concurrent/Callable<T>> tasks) ` Executes the given tasks, returning the result of one that has completed successfully (i.e., without throwing an exception), if any do. | | ` <T> T` | ` https://developer.android.com/reference/java/util/concurrent/AbstractExecutorService#invokeAny(java.util.Collection<?%20extends%20java.util.concurrent.Callable<T>>,%20long,%20java.util.concurrent.TimeUnit)(https://developer.android.com/reference/java/util/Collection<? extends https://developer.android.com/reference/java/util/concurrent/Callable<T>> tasks, long timeout, https://developer.android.com/reference/java/util/concurrent/TimeUnit unit) ` Executes the given tasks, returning the result of one that has completed successfully (i.e., without throwing an exception), if any do before the given timeout elapses. | | ` <T> https://developer.android.com/reference/java/util/concurrent/RunnableFuture<T>` | ` https://developer.android.com/reference/java/util/concurrent/AbstractExecutorService#newTaskFor(java.lang.Runnable,%20T)(https://developer.android.com/reference/java/lang/Runnable runnable, T value) ` Returns a `RunnableFuture` for the given runnable and default value. | | ` <T> https://developer.android.com/reference/java/util/concurrent/RunnableFuture<T>` | ` https://developer.android.com/reference/java/util/concurrent/AbstractExecutorService#newTaskFor(java.util.concurrent.Callable<T>)(https://developer.android.com/reference/java/util/concurrent/Callable<T> callable) ` Returns a `RunnableFuture` for the given callable task. | | ` <T> https://developer.android.com/reference/java/util/concurrent/Future<T>` | ` https://developer.android.com/reference/java/util/concurrent/AbstractExecutorService#submit(java.util.concurrent.Callable<T>)(https://developer.android.com/reference/java/util/concurrent/Callable<T> task) ` Submits a value-returning task for execution and returns a Future representing the pending results of the task. | | ` <T> https://developer.android.com/reference/java/util/concurrent/Future<T>` | ` https://developer.android.com/reference/java/util/concurrent/AbstractExecutorService#submit(java.lang.Runnable,%20T)(https://developer.android.com/reference/java/lang/Runnable task, T result) ` Submits a Runnable task for execution and returns a Future representing that task. | | ` https://developer.android.com/reference/java/util/concurrent/Future<?>` | ` https://developer.android.com/reference/java/util/concurrent/AbstractExecutorService#submit(java.lang.Runnable)(https://developer.android.com/reference/java/lang/Runnable task) ` Submits a Runnable task for execution and returns a Future representing that task. | ||
| From class ` https://developer.android.com/reference/java/lang/Object ` |---|---| | ` https://developer.android.com/reference/java/lang/Object` | ` https://developer.android.com/reference/java/lang/Object#clone()() ` Creates and returns a copy of this object. | | ` boolean` | ` https://developer.android.com/reference/java/lang/Object#equals(java.lang.Object)(https://developer.android.com/reference/java/lang/Object obj) ` Indicates whether some other object is "equal to" this one. | | ` void` | ` https://developer.android.com/reference/java/lang/Object#finalize()() ` Called by the garbage collector on an object when garbage collection determines that there are no more references to the object. | | ` final https://developer.android.com/reference/java/lang/Class<?>` | ` https://developer.android.com/reference/java/lang/Object#getClass()() ` Returns the runtime class of this `Object`. | | ` int` | ` https://developer.android.com/reference/java/lang/Object#hashCode()() ` Returns a hash code value for the object. | | ` final void` | ` https://developer.android.com/reference/java/lang/Object#notify()() ` Wakes up a single thread that is waiting on this object's monitor. | | ` final void` | ` https://developer.android.com/reference/java/lang/Object#notifyAll()() ` Wakes up all threads that are waiting on this object's monitor. | | ` https://developer.android.com/reference/java/lang/String` | ` https://developer.android.com/reference/java/lang/Object#toString()() ` Returns a string representation of the object. | | ` final void` | ` https://developer.android.com/reference/java/lang/Object#wait(long,%20int)(long timeoutMillis, int nanos) ` Causes the current thread to wait until it is awakened, typically by being *notified* or *interrupted*, or until a certain amount of real time has elapsed. | | ` final void` | ` https://developer.android.com/reference/java/lang/Object#wait(long)(long timeoutMillis) ` Causes the current thread to wait until it is awakened, typically by being *notified* or *interrupted*, or until a certain amount of real time has elapsed. | | ` final void` | ` https://developer.android.com/reference/java/lang/Object#wait()() ` Causes the current thread to wait until it is awakened, typically by being *notified* or *interrupted*. | ||
| From interface ` https://developer.android.com/reference/java/util/concurrent/ExecutorService ` |---|---| | ` abstract boolean` | ` https://developer.android.com/reference/java/util/concurrent/ExecutorService#awaitTermination(long,%20java.util.concurrent.TimeUnit)(long timeout, https://developer.android.com/reference/java/util/concurrent/TimeUnit unit) ` Blocks until all tasks have completed execution after a shutdown request, or the timeout occurs, or the current thread is interrupted, whichever happens first. | | ` default void` | ` https://developer.android.com/reference/java/util/concurrent/ExecutorService#close()() ` Initiates an orderly shutdown in which previously submitted tasks are executed, but no new tasks will be accepted. | | ` abstract <T> https://developer.android.com/reference/java/util/List<https://developer.android.com/reference/java/util/concurrent/Future<T>>` | ` https://developer.android.com/reference/java/util/concurrent/ExecutorService#invokeAll(java.util.Collection<?%20extends%20java.util.concurrent.Callable<T>>)(https://developer.android.com/reference/java/util/Collection<? extends https://developer.android.com/reference/java/util/concurrent/Callable<T>> tasks) ` Executes the given tasks, returning a list of Futures holding their status and results when all complete. | | ` abstract <T> https://developer.android.com/reference/java/util/List<https://developer.android.com/reference/java/util/concurrent/Future<T>>` | ` https://developer.android.com/reference/java/util/concurrent/ExecutorService#invokeAll(java.util.Collection<?%20extends%20java.util.concurrent.Callable<T>>,%20long,%20java.util.concurrent.TimeUnit)(https://developer.android.com/reference/java/util/Collection<? extends https://developer.android.com/reference/java/util/concurrent/Callable<T>> tasks, long timeout, https://developer.android.com/reference/java/util/concurrent/TimeUnit unit) ` Executes the given tasks, returning a list of Futures holding their status and results when all complete or the timeout expires, whichever happens first. | | ` abstract <T> T` | ` https://developer.android.com/reference/java/util/concurrent/ExecutorService#invokeAny(java.util.Collection<?%20extends%20java.util.concurrent.Callable<T>>)(https://developer.android.com/reference/java/util/Collection<? extends https://developer.android.com/reference/java/util/concurrent/Callable<T>> tasks) ` Executes the given tasks, returning the result of one that has completed successfully (i.e., without throwing an exception), if any do. | | ` abstract <T> T` | ` https://developer.android.com/reference/java/util/concurrent/ExecutorService#invokeAny(java.util.Collection<?%20extends%20java.util.concurrent.Callable<T>>,%20long,%20java.util.concurrent.TimeUnit)(https://developer.android.com/reference/java/util/Collection<? extends https://developer.android.com/reference/java/util/concurrent/Callable<T>> tasks, long timeout, https://developer.android.com/reference/java/util/concurrent/TimeUnit unit) ` Executes the given tasks, returning the result of one that has completed successfully (i.e., without throwing an exception), if any do before the given timeout elapses. | | ` abstract boolean` | ` https://developer.android.com/reference/java/util/concurrent/ExecutorService#isShutdown()() ` Returns `true` if this executor has been shut down. | | ` abstract boolean` | ` https://developer.android.com/reference/java/util/concurrent/ExecutorService#isTerminated()() ` Returns `true` if all tasks have completed following shut down. | | ` abstract void` | ` https://developer.android.com/reference/java/util/concurrent/ExecutorService#shutdown()() ` Initiates an orderly shutdown in which previously submitted tasks are executed, but no new tasks will be accepted. | | ` abstract https://developer.android.com/reference/java/util/List<https://developer.android.com/reference/java/lang/Runnable>` | ` https://developer.android.com/reference/java/util/concurrent/ExecutorService#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. | | ` abstract https://developer.android.com/reference/java/util/concurrent/Future<?>` | ` https://developer.android.com/reference/java/util/concurrent/ExecutorService#submit(java.lang.Runnable)(https://developer.android.com/reference/java/lang/Runnable task) ` Submits a Runnable task for execution and returns a Future representing that task. | | ` abstract <T> https://developer.android.com/reference/java/util/concurrent/Future<T>` | ` https://developer.android.com/reference/java/util/concurrent/ExecutorService#submit(java.util.concurrent.Callable<T>)(https://developer.android.com/reference/java/util/concurrent/Callable<T> task) ` Submits a value-returning task for execution and returns a Future representing the pending results of the task. | | ` abstract <T> https://developer.android.com/reference/java/util/concurrent/Future<T>` | ` https://developer.android.com/reference/java/util/concurrent/ExecutorService#submit(java.lang.Runnable,%20T)(https://developer.android.com/reference/java/lang/Runnable task, T result) ` Submits a Runnable task for execution and returns a Future representing that task. | ||
| From interface ` https://developer.android.com/reference/java/util/concurrent/ScheduledExecutorService ` |---|---| | ` abstract <V> https://developer.android.com/reference/java/util/concurrent/ScheduledFuture<V>` | ` https://developer.android.com/reference/java/util/concurrent/ScheduledExecutorService#schedule(java.util.concurrent.Callable<V>,%20long,%20java.util.concurrent.TimeUnit)(https://developer.android.com/reference/java/util/concurrent/Callable<V> callable, long delay, https://developer.android.com/reference/java/util/concurrent/TimeUnit unit) ` Submits a value-returning one-shot task that becomes enabled after the given delay. | | ` abstract https://developer.android.com/reference/java/util/concurrent/ScheduledFuture<?>` | ` https://developer.android.com/reference/java/util/concurrent/ScheduledExecutorService#schedule(java.lang.Runnable,%20long,%20java.util.concurrent.TimeUnit)(https://developer.android.com/reference/java/lang/Runnable command, long delay, https://developer.android.com/reference/java/util/concurrent/TimeUnit unit) ` Submits a one-shot task that becomes enabled after the given delay. | | ` abstract https://developer.android.com/reference/java/util/concurrent/ScheduledFuture<?>` | ` https://developer.android.com/reference/java/util/concurrent/ScheduledExecutorService#scheduleAtFixedRate(java.lang.Runnable,%20long,%20long,%20java.util.concurrent.TimeUnit)(https://developer.android.com/reference/java/lang/Runnable command, long initialDelay, long period, https://developer.android.com/reference/java/util/concurrent/TimeUnit unit) ` Submits a periodic action that becomes enabled first after the given initial delay, and subsequently with the given period; that is, executions will commence after `initialDelay`, then `initialDelay + period`, then `initialDelay + 2 * period`, and so on. | | ` abstract https://developer.android.com/reference/java/util/concurrent/ScheduledFuture<?>` | ` https://developer.android.com/reference/java/util/concurrent/ScheduledExecutorService#scheduleWithFixedDelay(java.lang.Runnable,%20long,%20long,%20java.util.concurrent.TimeUnit)(https://developer.android.com/reference/java/lang/Runnable command, long initialDelay, long delay, https://developer.android.com/reference/java/util/concurrent/TimeUnit unit) ` Submits a periodic action that becomes enabled first after the given initial delay, and subsequently with the given delay between the termination of one execution and the commencement of the next. | ||
| From interface ` https://developer.android.com/reference/java/lang/AutoCloseable ` |---|---| | ` abstract void` | ` https://developer.android.com/reference/java/lang/AutoCloseable#close()() ` Closes this resource, relinquishing any underlying resources. | ||
| From interface ` https://developer.android.com/reference/java/util/concurrent/Executor ` |---|---| | ` abstract void` | ` https://developer.android.com/reference/java/util/concurrent/Executor#execute(java.lang.Runnable)(https://developer.android.com/reference/java/lang/Runnable command) ` Executes the given command at some time in the future. | ||

## Public constructors

### ScheduledThreadPoolExecutor

Added in [API level 1](https://developer.android.com/guide/topics/manifest/uses-sdk-element#ApiLevels)

```
public ScheduledThreadPoolExecutor (int corePoolSize)
```

Creates a new `ScheduledThreadPoolExecutor` with the
given core pool size.

<br />

| Parameters ||
|---|---|
| `corePoolSize` | `int`: the number of threads to keep in the pool, even if they are idle, unless `allowCoreThreadTimeOut` is set <br /> |

| Throws ||
|---|---|
| `https://developer.android.com/reference/java/lang/IllegalArgumentException` | if `corePoolSize < 0` |

### ScheduledThreadPoolExecutor

Added in [API level 1](https://developer.android.com/guide/topics/manifest/uses-sdk-element#ApiLevels)

```
public ScheduledThreadPoolExecutor (int corePoolSize, 
                RejectedExecutionHandler handler)
```

Creates a new `ScheduledThreadPoolExecutor` with the
given initial parameters.

<br />

| Parameters ||
|---|---|
| `corePoolSize` | `int`: the number of threads to keep in the pool, even if they are idle, unless `allowCoreThreadTimeOut` is set <br /> |
| `handler` | `RejectedExecutionHandler`: the handler to use when execution is blocked because the thread bounds and queue capacities are reached <br /> |

| Throws ||
|---|---|
| `https://developer.android.com/reference/java/lang/IllegalArgumentException` | if `corePoolSize < 0` |
| `https://developer.android.com/reference/java/lang/NullPointerException` | if `handler` is null |

### ScheduledThreadPoolExecutor

Added in [API level 1](https://developer.android.com/guide/topics/manifest/uses-sdk-element#ApiLevels)

```
public ScheduledThreadPoolExecutor (int corePoolSize, 
                ThreadFactory threadFactory)
```

Creates a new `ScheduledThreadPoolExecutor` with the
given initial parameters.

<br />

| Parameters ||
|---|---|
| `corePoolSize` | `int`: the number of threads to keep in the pool, even if they are idle, unless `allowCoreThreadTimeOut` is set <br /> |
| `threadFactory` | `ThreadFactory`: the factory to use when the executor creates a new thread <br /> |

| Throws ||
|---|---|
| `https://developer.android.com/reference/java/lang/IllegalArgumentException` | if `corePoolSize < 0` |
| `https://developer.android.com/reference/java/lang/NullPointerException` | if `threadFactory` is null |

### ScheduledThreadPoolExecutor

Added in [API level 1](https://developer.android.com/guide/topics/manifest/uses-sdk-element#ApiLevels)

```
public ScheduledThreadPoolExecutor (int corePoolSize, 
                ThreadFactory threadFactory, 
                RejectedExecutionHandler handler)
```

Creates a new `ScheduledThreadPoolExecutor` with the
given initial parameters.

<br />

| Parameters ||
|---|---|
| `corePoolSize` | `int`: the number of threads to keep in the pool, even if they are idle, unless `allowCoreThreadTimeOut` is set <br /> |
| `threadFactory` | `ThreadFactory`: the factory to use when the executor creates a new thread <br /> |
| `handler` | `RejectedExecutionHandler`: the handler to use when execution is blocked because the thread bounds and queue capacities are reached <br /> |

| Throws ||
|---|---|
| `https://developer.android.com/reference/java/lang/IllegalArgumentException` | if `corePoolSize < 0` |
| `https://developer.android.com/reference/java/lang/NullPointerException` | if `threadFactory` or `handler` is null |

## Public methods

### execute

Added in [API level 1](https://developer.android.com/guide/topics/manifest/uses-sdk-element#ApiLevels)

```
public void execute (Runnable command)
```

Executes `command` with zero required delay.
This has effect equivalent to
`https://developer.android.com/reference/java/util/concurrent/ScheduledThreadPoolExecutor#schedule(java.lang.Runnable,%20long,%20java.util.concurrent.TimeUnit)`.
Note that inspections of the queue and of the list returned by
`shutdownNow` will access the zero-delayed
`https://developer.android.com/reference/java/util/concurrent/ScheduledFuture`, not the `command` itself.

A consequence of the use of `ScheduledFuture` objects is
that `https://developer.android.com/reference/java/util/concurrent/ThreadPoolExecutor#afterExecute(java.lang.Runnable,%20java.lang.Throwable)` 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 `https://developer.android.com/reference/java/util/concurrent/Future#get()`.

<br />

| Parameters ||
|---|---|
| `command` | `Runnable`: the task to execute <br /> |

| Throws ||
|---|---|
| `https://developer.android.com/reference/java/lang/NullPointerException` |   |
| `https://developer.android.com/reference/java/util/concurrent/RejectedExecutionException` | at discretion of `RejectedExecutionHandler`, if the task cannot be accepted for execution because the executor has been shut down |

### getContinueExistingPeriodicTasksAfterShutdownPolicy

Added in [API level 1](https://developer.android.com/guide/topics/manifest/uses-sdk-element#ApiLevels)

```
public boolean getContinueExistingPeriodicTasksAfterShutdownPolicy ()
```

Gets the policy on whether to continue executing existing
periodic tasks even when this executor has been `shutdown`.
In this case, executions will continue until `shutdownNow`
or the policy is set to `false` when already shutdown.
This value is by default `false`.

<br />

| Returns ||
|---|---|
| `boolean` | `true` if will continue after shutdown <br /> |

**See also:**

- `https://developer.android.com/reference/java/util/concurrent/ScheduledThreadPoolExecutor#setContinueExistingPeriodicTasksAfterShutdownPolicy(boolean)`

### getExecuteExistingDelayedTasksAfterShutdownPolicy

Added in [API level 1](https://developer.android.com/guide/topics/manifest/uses-sdk-element#ApiLevels)

```
public boolean getExecuteExistingDelayedTasksAfterShutdownPolicy ()
```

Gets the policy on whether to execute existing delayed
tasks even when this executor has been `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`.

<br />

| Returns ||
|---|---|
| `boolean` | `true` if will execute after shutdown <br /> |

**See also:**

- `https://developer.android.com/reference/java/util/concurrent/ScheduledThreadPoolExecutor#setExecuteExistingDelayedTasksAfterShutdownPolicy(boolean)`

### getQueue

Added in [API level 1](https://developer.android.com/guide/topics/manifest/uses-sdk-element#ApiLevels)

```
public BlockingQueue<Runnable> getQueue ()
```

Returns the task queue used by this executor. Access to the
task queue is intended primarily for debugging and monitoring.
This queue may be in active use. Retrieving the task queue
does not prevent queued tasks from executing.

Each element of this queue is a `https://developer.android.com/reference/java/util/concurrent/ScheduledFuture`.
For tasks submitted via one of the `schedule` methods, the
element will be identical to the returned `ScheduledFuture`.
For tasks submitted using `https://developer.android.com/reference/java/util/concurrent/ScheduledThreadPoolExecutor#execute(java.lang.Runnable)`, the element
will be a zero-delay `ScheduledFuture`.

Iteration over this queue is *not* guaranteed to traverse
tasks in the order in which they will execute.

<br />

| Returns ||
|---|---|
| `https://developer.android.com/reference/java/util/concurrent/BlockingQueue<https://developer.android.com/reference/java/lang/Runnable>` | the task queue <br /> |

### getRemoveOnCancelPolicy

Added in [API level 21](https://developer.android.com/guide/topics/manifest/uses-sdk-element#ApiLevels)

```
public boolean getRemoveOnCancelPolicy ()
```

Gets the policy on whether cancelled tasks should be immediately
removed from the work queue at time of cancellation. This value is
by default `false`.

<br />

| Returns ||
|---|---|
| `boolean` | `true` if cancelled tasks are immediately removed from the queue <br /> |

**See also:**

- `https://developer.android.com/reference/java/util/concurrent/ScheduledThreadPoolExecutor#setRemoveOnCancelPolicy(boolean)`

### schedule

Added in [API level 1](https://developer.android.com/guide/topics/manifest/uses-sdk-element#ApiLevels)

```
public ScheduledFuture<V> schedule (Callable<V> callable, 
                long delay, 
                TimeUnit unit)
```

Submits a value-returning one-shot task that becomes enabled
after the given delay.

<br />

| Parameters ||
|---|---|
| `callable` | `Callable`: the function to execute <br /> |
| `delay` | `long`: the time from now to delay execution <br /> |
| `unit` | `TimeUnit`: the time unit of the delay parameter <br /> |

| Returns ||
|---|---|
| `https://developer.android.com/reference/java/util/concurrent/ScheduledFuture<V>` | a ScheduledFuture that can be used to extract result or cancel <br /> |

| Throws ||
|---|---|
| `https://developer.android.com/reference/java/lang/NullPointerException` |   |
| `https://developer.android.com/reference/java/util/concurrent/RejectedExecutionException` |   |

### schedule

Added in [API level 1](https://developer.android.com/guide/topics/manifest/uses-sdk-element#ApiLevels)

```
public ScheduledFuture<?> schedule (Runnable command, 
                long delay, 
                TimeUnit unit)
```

Submits a one-shot task that becomes enabled after the given delay.

<br />

| Parameters ||
|---|---|
| `command` | `Runnable`: the task to execute <br /> |
| `delay` | `long`: the time from now to delay execution <br /> |
| `unit` | `TimeUnit`: the time unit of the delay parameter <br /> |

| Returns ||
|---|---|
| `https://developer.android.com/reference/java/util/concurrent/ScheduledFuture<?>` | a ScheduledFuture representing pending completion of the task and whose `get()` method will return `null` upon completion <br /> |

| Throws ||
|---|---|
| `https://developer.android.com/reference/java/lang/NullPointerException` |   |
| `https://developer.android.com/reference/java/util/concurrent/RejectedExecutionException` |   |

### scheduleAtFixedRate

Added in [API level 1](https://developer.android.com/guide/topics/manifest/uses-sdk-element#ApiLevels)

```
public ScheduledFuture<?> scheduleAtFixedRate (Runnable command, 
                long initialDelay, 
                long period, 
                TimeUnit unit)
```

Submits a periodic action that becomes enabled first after the
given initial delay, and subsequently with the given period;
that is, executions will commence after
`initialDelay`, then `initialDelay + period`, then
`initialDelay + 2 * period`, and so on.

The sequence of task executions continues indefinitely until
one of the following exceptional completions occur:

- The task is [explicitly cancelled](https://developer.android.com/reference/java/util/concurrent/Future#cancel(boolean)) via the returned future.
- Method `https://developer.android.com/reference/java/util/concurrent/ScheduledThreadPoolExecutor#shutdown()` is called and the [policy on
  whether to continue after shutdown](https://developer.android.com/reference/java/util/concurrent/ScheduledThreadPoolExecutor#getContinueExistingPeriodicTasksAfterShutdownPolicy()) is not set true, or method `https://developer.android.com/reference/java/util/concurrent/ScheduledThreadPoolExecutor#shutdownNow()` is called; also resulting in task cancellation.
- An execution of the task throws an exception. In this case calling `https://developer.android.com/reference/java/util/concurrent/Future#get()` on the returned future will throw `https://developer.android.com/reference/java/util/concurrent/ExecutionException`, holding the exception as its cause.

Subsequent executions are suppressed. Subsequent calls to `https://developer.android.com/reference/java/util/concurrent/Future#isDone()` on the returned future will return `true`.

<br />

<br />

| Parameters ||
|---|---|
| `command` | `Runnable`: the task to execute <br /> |
| `initialDelay` | `long`: the time to delay first execution <br /> |
| `period` | `long`: the period between successive executions <br /> |
| `unit` | `TimeUnit`: the time unit of the initialDelay and period parameters <br /> |

| Returns ||
|---|---|
| `https://developer.android.com/reference/java/util/concurrent/ScheduledFuture<?>` | a ScheduledFuture representing pending completion of the series of repeated tasks. The future's `https://developer.android.com/reference/java/util/concurrent/Future#get()` method will never return normally, and will throw an exception upon task cancellation or abnormal termination of a task execution. <br /> |

| Throws ||
|---|---|
| `https://developer.android.com/reference/java/lang/IllegalArgumentException` |   |
| `https://developer.android.com/reference/java/lang/NullPointerException` |   |
| `https://developer.android.com/reference/java/util/concurrent/RejectedExecutionException` |   |

### scheduleWithFixedDelay

Added in [API level 1](https://developer.android.com/guide/topics/manifest/uses-sdk-element#ApiLevels)

```
public ScheduledFuture<?> scheduleWithFixedDelay (Runnable command, 
                long initialDelay, 
                long delay, 
                TimeUnit unit)
```

Submits a periodic action that becomes enabled first after the
given initial delay, and subsequently with the given delay
between the termination of one execution and the commencement of
the next.

The sequence of task executions continues indefinitely until
one of the following exceptional completions occur:

- The task is [explicitly cancelled](https://developer.android.com/reference/java/util/concurrent/Future#cancel(boolean)) via the returned future.
- Method `https://developer.android.com/reference/java/util/concurrent/ScheduledThreadPoolExecutor#shutdown()` is called and the [policy on
  whether to continue after shutdown](https://developer.android.com/reference/java/util/concurrent/ScheduledThreadPoolExecutor#getContinueExistingPeriodicTasksAfterShutdownPolicy()) is not set true, or method `https://developer.android.com/reference/java/util/concurrent/ScheduledThreadPoolExecutor#shutdownNow()` is called; also resulting in task cancellation.
- An execution of the task throws an exception. In this case calling `https://developer.android.com/reference/java/util/concurrent/Future#get()` on the returned future will throw `https://developer.android.com/reference/java/util/concurrent/ExecutionException`, holding the exception as its cause.

Subsequent executions are suppressed. Subsequent calls to `https://developer.android.com/reference/java/util/concurrent/Future#isDone()` on the returned future will return `true`.

<br />

<br />

| Parameters ||
|---|---|
| `command` | `Runnable`: the task to execute <br /> |
| `initialDelay` | `long`: the time to delay first execution <br /> |
| `delay` | `long`: the delay between the termination of one execution and the commencement of the next <br /> |
| `unit` | `TimeUnit`: the time unit of the initialDelay and delay parameters <br /> |

| Returns ||
|---|---|
| `https://developer.android.com/reference/java/util/concurrent/ScheduledFuture<?>` | a ScheduledFuture representing pending completion of the series of repeated tasks. The future's `https://developer.android.com/reference/java/util/concurrent/Future#get()` method will never return normally, and will throw an exception upon task cancellation or abnormal termination of a task execution. <br /> |

| Throws ||
|---|---|
| `https://developer.android.com/reference/java/lang/IllegalArgumentException` |   |
| `https://developer.android.com/reference/java/lang/NullPointerException` |   |
| `https://developer.android.com/reference/java/util/concurrent/RejectedExecutionException` |   |

### setContinueExistingPeriodicTasksAfterShutdownPolicy

Added in [API level 1](https://developer.android.com/guide/topics/manifest/uses-sdk-element#ApiLevels)

```
public void setContinueExistingPeriodicTasksAfterShutdownPolicy (boolean value)
```

Sets the policy on whether to continue executing existing
periodic tasks even when this executor has been `shutdown`.
In this case, executions will continue until `shutdownNow`
or the policy is set to `false` when already shutdown.
This value is by default `false`.

<br />

| Parameters ||
|---|---|
| `value` | `boolean`: if `true`, continue after shutdown, else don't <br /> |

**See also:**

- `https://developer.android.com/reference/java/util/concurrent/ScheduledThreadPoolExecutor#getContinueExistingPeriodicTasksAfterShutdownPolicy()`

### setExecuteExistingDelayedTasksAfterShutdownPolicy

Added in [API level 1](https://developer.android.com/guide/topics/manifest/uses-sdk-element#ApiLevels)

```
public void setExecuteExistingDelayedTasksAfterShutdownPolicy (boolean value)
```

Sets the policy on whether to execute existing delayed
tasks even when this executor has been `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`.

<br />

| Parameters ||
|---|---|
| `value` | `boolean`: if `true`, execute after shutdown, else don't <br /> |

**See also:**

- `https://developer.android.com/reference/java/util/concurrent/ScheduledThreadPoolExecutor#getExecuteExistingDelayedTasksAfterShutdownPolicy()`

### setRemoveOnCancelPolicy

Added in [API level 21](https://developer.android.com/guide/topics/manifest/uses-sdk-element#ApiLevels)

```
public void setRemoveOnCancelPolicy (boolean value)
```

Sets the policy on whether cancelled tasks should be immediately
removed from the work queue at time of cancellation. This value is
by default `false`.

<br />

| Parameters ||
|---|---|
| `value` | `boolean`: if `true`, remove on cancellation, else don't <br /> |

**See also:**

- `https://developer.android.com/reference/java/util/concurrent/ScheduledThreadPoolExecutor#getRemoveOnCancelPolicy()`

### shutdown

Added in [API level 1](https://developer.android.com/guide/topics/manifest/uses-sdk-element#ApiLevels)

```
public void shutdown ()
```

Initiates an orderly shutdown in which previously submitted
tasks are executed, but no new tasks will be accepted.
Invocation has no additional effect if already shut down.

This method does not wait for previously submitted tasks to
complete execution. Use `https://developer.android.com/reference/java/util/concurrent/ThreadPoolExecutor#awaitTermination(long,%20java.util.concurrent.TimeUnit)`
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.

<br />

### shutdownNow

Added in [API level 1](https://developer.android.com/guide/topics/manifest/uses-sdk-element#ApiLevels)

```
public List<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. These tasks are drained (removed)
from the task queue upon return from this method.

This method does not wait for actively executing tasks to
terminate. Use `https://developer.android.com/reference/java/util/concurrent/ThreadPoolExecutor#awaitTermination(long,%20java.util.concurrent.TimeUnit)` to
do that.

There are no guarantees beyond best-effort attempts to stop
processing actively executing tasks. This implementation
interrupts tasks via `https://developer.android.com/reference/java/lang/Thread#interrupt()`; any task that
fails to respond to interrupts may never terminate.

<br />

| Returns ||
|---|---|
| `https://developer.android.com/reference/java/util/List<https://developer.android.com/reference/java/lang/Runnable>` | list of tasks that never commenced execution. Each element of this list is a `https://developer.android.com/reference/java/util/concurrent/ScheduledFuture`. For tasks submitted via one of the `schedule` methods, the element will be identical to the returned `ScheduledFuture`. For tasks submitted using `https://developer.android.com/reference/java/util/concurrent/ScheduledThreadPoolExecutor#execute(java.lang.Runnable)`, the element will be a zero-delay `ScheduledFuture`. <br /> |

### submit

Added in [API level 1](https://developer.android.com/guide/topics/manifest/uses-sdk-element#ApiLevels)

```
public Future<?> submit (Runnable task)
```

Submits a Runnable task for execution and returns a Future
representing that task. The Future's `get` method will
return `null` upon *successful* completion.

<br />

| Parameters ||
|---|---|
| `task` | `Runnable`: the task to submit <br /> |

| Returns ||
|---|---|
| `https://developer.android.com/reference/java/util/concurrent/Future<?>` | a Future representing pending completion of the task <br /> |

| Throws ||
|---|---|
| `https://developer.android.com/reference/java/lang/NullPointerException` |   |
| `https://developer.android.com/reference/java/util/concurrent/RejectedExecutionException` |   |

### submit

Added in [API level 1](https://developer.android.com/guide/topics/manifest/uses-sdk-element#ApiLevels)

```
public Future<T> submit (Callable<T> task)
```

Submits a value-returning task for execution and returns a
Future representing the pending results of the task. The
Future's `get` method will return the task's result upon
successful completion.


If you would like to immediately block waiting
for a task, you can use constructions of the form
`result = exec.submit(aCallable).get();`

Note: The `https://developer.android.com/reference/java/util/concurrent/Executors` class includes a set of methods
that can convert some other common closure-like objects,
for example, `https://developer.android.com/reference/java/security/PrivilegedAction` to
`https://developer.android.com/reference/java/util/concurrent/Callable` form so they can be submitted.

<br />

| Parameters ||
|---|---|
| `task` | `Callable`: the task to submit <br /> |

| Returns ||
|---|---|
| `https://developer.android.com/reference/java/util/concurrent/Future<T>` | a Future representing pending completion of the task <br /> |

| Throws ||
|---|---|
| `https://developer.android.com/reference/java/lang/NullPointerException` |   |
| `https://developer.android.com/reference/java/util/concurrent/RejectedExecutionException` |   |

### submit

Added in [API level 1](https://developer.android.com/guide/topics/manifest/uses-sdk-element#ApiLevels)

```
public Future<T> submit (Runnable task, 
                T result)
```

Submits a Runnable task for execution and returns a Future
representing that task. The Future's `get` method will
return the given result upon successful completion.

<br />

| Parameters ||
|---|---|
| `task` | `Runnable`: the task to submit <br /> |
| `result` | `T`: the result to return <br /> |

| Returns ||
|---|---|
| `https://developer.android.com/reference/java/util/concurrent/Future<T>` | a Future representing pending completion of the task <br /> |

| Throws ||
|---|---|
| `https://developer.android.com/reference/java/lang/NullPointerException` |   |
| `https://developer.android.com/reference/java/util/concurrent/RejectedExecutionException` |   |

## Protected methods

### decorateTask

Added in [API level 9](https://developer.android.com/guide/topics/manifest/uses-sdk-element#ApiLevels)

```
protected RunnableScheduledFuture<V> decorateTask (Runnable runnable, 
                RunnableScheduledFuture<V> task)
```

Modifies or replaces the task used to execute a runnable.
This method can be used to override the concrete
class used for managing internal tasks.
The default implementation simply returns the given task.

<br />

| Parameters ||
|---|---|
| `runnable` | `Runnable`: the submitted Runnable <br /> |
| `task` | `RunnableScheduledFuture`: the task created to execute the runnable <br /> |

| Returns ||
|---|---|
| `https://developer.android.com/reference/java/util/concurrent/RunnableScheduledFuture<V>` | a task that can execute the runnable <br /> |

### decorateTask

Added in [API level 9](https://developer.android.com/guide/topics/manifest/uses-sdk-element#ApiLevels)

```
protected RunnableScheduledFuture<V> decorateTask (Callable<V> callable, 
                RunnableScheduledFuture<V> task)
```

Modifies or replaces the task used to execute a callable.
This method can be used to override the concrete
class used for managing internal tasks.
The default implementation simply returns the given task.

<br />

| Parameters ||
|---|---|
| `callable` | `Callable`: the submitted Callable <br /> |
| `task` | `RunnableScheduledFuture`: the task created to execute the callable <br /> |

| Returns ||
|---|---|
| `https://developer.android.com/reference/java/util/concurrent/RunnableScheduledFuture<V>` | a task that can execute the callable <br /> |