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/AbstractExecutorService#pubctors) \| [Methods](https://developer.android.com/reference/java/util/concurrent/AbstractExecutorService#pubmethods) \| [Protected Methods](https://developer.android.com/reference/java/util/concurrent/AbstractExecutorService#promethods) \| [Inherited Methods](https://developer.android.com/reference/java/util/concurrent/AbstractExecutorService#inhmethods)

# AbstractExecutorService


`
public


abstract
class
AbstractExecutorService
`


`

extends https://developer.android.com/reference/java/lang/Object


`

`


implements

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


`

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

|---|
| Known direct subclasses [ForkJoinPool](https://developer.android.com/reference/java/util/concurrent/ForkJoinPool), [ThreadPoolExecutor](https://developer.android.com/reference/java/util/concurrent/ThreadPoolExecutor) |---|---| | [ForkJoinPool](https://developer.android.com/reference/java/util/concurrent/ForkJoinPool) | An `https://developer.android.com/reference/java/util/concurrent/ExecutorService` for running `https://developer.android.com/reference/java/util/concurrent/ForkJoinTask`s. | | [ThreadPoolExecutor](https://developer.android.com/reference/java/util/concurrent/ThreadPoolExecutor) | An `https://developer.android.com/reference/java/util/concurrent/ExecutorService` that executes each submitted task using one of possibly several pooled threads, normally configured using `https://developer.android.com/reference/java/util/concurrent/Executors` factory methods. | |

|---|
| Known indirect subclasses [ScheduledThreadPoolExecutor](https://developer.android.com/reference/java/util/concurrent/ScheduledThreadPoolExecutor) |---|---| | [ScheduledThreadPoolExecutor](https://developer.android.com/reference/java/util/concurrent/ScheduledThreadPoolExecutor) | 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. | |

<br />

*** ** * ** ***

Provides default implementations of `https://developer.android.com/reference/java/util/concurrent/ExecutorService`
execution methods. This class implements the `submit`,
`invokeAny` and `invokeAll` methods using a
`https://developer.android.com/reference/java/util/concurrent/RunnableFuture` returned by `newTaskFor`, which defaults
to the `https://developer.android.com/reference/java/util/concurrent/FutureTask` class provided in this package. For example,
the implementation of `submit(Runnable)` creates an
associated `RunnableFuture` that is executed and
returned. Subclasses may override the `newTaskFor` methods
to return `RunnableFuture` implementations other than
`FutureTask`.

**Extension example.** Here is a sketch of a class
that customizes `https://developer.android.com/reference/java/util/concurrent/ThreadPoolExecutor` to use
a `CustomTask` class instead of the default `FutureTask`:

    public class CustomThreadPoolExecutor extends ThreadPoolExecutor {

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

      protected <V> RunnableFuture<V> newTaskFor(Callable<V> c) {
          return new CustomTask<V>(c);
      }
      protected <V> RunnableFuture<V> newTaskFor(Runnable r, V v) {
          return new CustomTask<V>(r, v);
      }
      // ... add constructors, etc.
    }

<br />

## Summary

| ### Public constructors ||
|---|---|
| ` https://developer.android.com/reference/java/util/concurrent/AbstractExecutorService#AbstractExecutorService()() ` Constructor for subclasses to call. |

| ### Public methods ||
|---|---|
| ` <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/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. |

| ### Protected methods ||
|---|---|
| ` <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. |

| ### Inherited methods |
|---|---|
| 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/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

### AbstractExecutorService

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

```
public AbstractExecutorService ()
```

Constructor for subclasses to call.

<br />

## Public methods

### invokeAll

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

```
public List<Future<T>> invokeAll (Collection<? extends Callable<T>> tasks)
```

Executes the given tasks, returning a list of Futures holding
their status and results when all complete.
`https://developer.android.com/reference/java/util/concurrent/Future#isDone()` is `true` for each
element of the returned list.
Note that a *completed* task could have
terminated either normally or by throwing an exception.
The results of this method are undefined if the given
collection is modified while this operation is in progress.

<br />

| Parameters ||
|---|---|
| `tasks` | `Collection`: the collection of tasks <br /> |

| Returns ||
|---|---|
| `https://developer.android.com/reference/java/util/List<https://developer.android.com/reference/java/util/concurrent/Future<T>>` | a list of Futures representing the tasks, in the same sequential order as produced by the iterator for the given task list, each of which has completed <br /> |

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

### invokeAll

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

```
public List<Future<T>> invokeAll (Collection<? extends Callable<T>> tasks, 
                long timeout, 
                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.
`https://developer.android.com/reference/java/util/concurrent/Future#isDone()` is `true` for each
element of the returned list.
Upon return, tasks that have not completed are cancelled.
Note that a *completed* task could have
terminated either normally or by throwing an exception.
The results of this method are undefined if the given
collection is modified while this operation is in progress.

<br />

| Parameters ||
|---|---|
| `tasks` | `Collection`: the collection of tasks <br /> |
| `timeout` | `long`: the maximum time to wait <br /> |
| `unit` | `TimeUnit`: the time unit of the timeout argument <br /> |

| Returns ||
|---|---|
| `https://developer.android.com/reference/java/util/List<https://developer.android.com/reference/java/util/concurrent/Future<T>>` | a list of Futures 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. <br /> |

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

### invokeAny

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

```
public T invokeAny (Collection<? extends 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. Upon normal or exceptional return,
tasks that have not completed are cancelled.
The results of this method are undefined if the given
collection is modified while this operation is in progress.

<br />

| Parameters ||
|---|---|
| `tasks` | `Collection`: the collection of tasks <br /> |

| Returns ||
|---|---|
| `T` | the result returned by one of the tasks <br /> |

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

### invokeAny

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

```
public T invokeAny (Collection<? extends Callable<T>> tasks, 
                long timeout, 
                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.
Upon normal or exceptional return, tasks that have not
completed are cancelled.
The results of this method are undefined if the given
collection is modified while this operation is in progress.

<br />

| Parameters ||
|---|---|
| `tasks` | `Collection`: the collection of tasks <br /> |
| `timeout` | `long`: the maximum time to wait <br /> |
| `unit` | `TimeUnit`: the time unit of the timeout argument <br /> |

| Returns ||
|---|---|
| `T` | the result returned by one of the tasks <br /> |

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

### 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` |   |

### 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` |   |

## Protected methods

### newTaskFor

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

```
protected RunnableFuture<T> newTaskFor (Runnable runnable, 
                T value)
```

Returns a `RunnableFuture` for the given runnable and default
value.

<br />

| Parameters ||
|---|---|
| `runnable` | `Runnable`: the runnable task being wrapped <br /> |
| `value` | `T`: the default value for the returned future <br /> |

| Returns ||
|---|---|
| `https://developer.android.com/reference/java/util/concurrent/RunnableFuture<T>` | a `RunnableFuture` which, when run, will run the underlying runnable and which, as a `Future`, will yield the given value as its result and provide for cancellation of the underlying task <br /> |

### newTaskFor

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

```
protected RunnableFuture<T> newTaskFor (Callable<T> callable)
```

Returns a `RunnableFuture` for the given callable task.

<br />

| Parameters ||
|---|---|
| `callable` | `Callable`: the callable task being wrapped <br /> |

| Returns ||
|---|---|
| `https://developer.android.com/reference/java/util/concurrent/RunnableFuture<T>` | a `RunnableFuture` which, when run, will call the underlying callable and which, as a `Future`, will yield the callable's result as its result and provide for cancellation of the underlying task <br /> |