Added in API level 1

AbstractExecutorService

abstract class AbstractExecutorService : ExecutorService
kotlin.Any
   ↳ java.util.concurrent.AbstractExecutorService

Provides default implementations of ExecutorService execution methods. This class implements the submit, invokeAny and invokeAll methods using a RunnableFuture returned by newTaskFor, which defaults to the 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 ThreadPoolExecutor to use a CustomTask class instead of the default FutureTask:

<code>public class CustomThreadPoolExecutor extends ThreadPoolExecutor {
 
    static class CustomTask&lt;V&gt; implements RunnableFuture&lt;V&gt; { ... }
 
    protected &lt;V&gt; RunnableFuture&lt;V&gt; newTaskFor(Callable&lt;V&gt; c) {
        return new CustomTask&lt;V&gt;(c);
    }
    protected &lt;V&gt; RunnableFuture&lt;V&gt; newTaskFor(Runnable r, V v) {
        return new CustomTask&lt;V&gt;(r, v);
    }
    // ... add constructors, etc.
  }</code>

Summary

Public constructors

Constructor for subclasses to call.

Public methods
open MutableList<Future<T>!>!

open MutableList<Future<T>!>!
invokeAll(tasks: MutableCollection<out Callable<T>!>!, timeout: Long, unit: TimeUnit!)

open T

open T
invokeAny(tasks: MutableCollection<out Callable<T>!>!, timeout: Long, unit: TimeUnit!)

open Future<*>!
submit(task: Runnable!)

open Future<T>!
submit(task: Runnable!, result: T)

open Future<T>!
submit(task: Callable<T>!)

Protected methods
open RunnableFuture<T>!
newTaskFor(runnable: Runnable!, value: T)

Returns a RunnableFuture for the given runnable and default value.

open RunnableFuture<T>!
newTaskFor(callable: Callable<T>!)

Returns a RunnableFuture for the given callable task.

Inherited functions

Public constructors

AbstractExecutorService

Added in API level 1
AbstractExecutorService()

Constructor for subclasses to call.

Public methods

invokeAll

Added in API level 1
open fun <T : Any!> invokeAll(tasks: MutableCollection<out Callable<T>!>!): MutableList<Future<T>!>!
Parameters
tasks MutableCollection<out Callable<T>!>!: the collection of tasks
<T> the type of the values returned from the tasks
Return
MutableList<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
Exceptions
java.lang.InterruptedException if interrupted while waiting, in which case unfinished tasks are cancelled
java.lang.NullPointerException if tasks or any of its elements are null
java.util.concurrent.RejectedExecutionException if any task cannot be scheduled for execution

invokeAll

Added in API level 1
open fun <T : Any!> invokeAll(
    tasks: MutableCollection<out Callable<T>!>!,
    timeout: Long,
    unit: TimeUnit!
): MutableList<Future<T>!>!
Parameters
tasks MutableCollection<out Callable<T>!>!: the collection of tasks
timeout Long: the maximum time to wait
unit TimeUnit!: the time unit of the timeout argument
<T> the type of the values returned from the tasks
Return
MutableList<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.
Exceptions
java.lang.InterruptedException if interrupted while waiting, in which case unfinished tasks are cancelled
java.lang.NullPointerException if tasks, any of its elements, or unit are null
java.util.concurrent.RejectedExecutionException if any task cannot be scheduled for execution

invokeAny

Added in API level 1
open fun <T : Any!> invokeAny(tasks: MutableCollection<out Callable<T>!>!): T
Parameters
tasks MutableCollection<out Callable<T>!>!: the collection of tasks
<T> the type of the values returned from the tasks
Return
T the result returned by one of the tasks
Exceptions
java.lang.InterruptedException if interrupted while waiting
java.lang.NullPointerException if tasks or any element task subject to execution is null
java.lang.IllegalArgumentException if tasks is empty
java.util.concurrent.ExecutionException if no task successfully completes
java.util.concurrent.RejectedExecutionException if tasks cannot be scheduled for execution

invokeAny

Added in API level 1
open fun <T : Any!> invokeAny(
    tasks: MutableCollection<out Callable<T>!>!,
    timeout: Long,
    unit: TimeUnit!
): T
Parameters
tasks MutableCollection<out Callable<T>!>!: the collection of tasks
timeout Long: the maximum time to wait
unit TimeUnit!: the time unit of the timeout argument
<T> the type of the values returned from the tasks
Return
T the result returned by one of the tasks
Exceptions
java.lang.InterruptedException if interrupted while waiting
java.lang.NullPointerException if tasks, or unit, or any element task subject to execution is null
java.util.concurrent.TimeoutException if the given timeout elapses before any task successfully completes
java.util.concurrent.ExecutionException if no task successfully completes
java.util.concurrent.RejectedExecutionException if tasks cannot be scheduled for execution

submit

Added in API level 1
open fun submit(task: Runnable!): Future<*>!
Parameters
task Runnable!: the task to submit
Return
Future<*>! a Future representing pending completion of the task
Exceptions
java.util.concurrent.RejectedExecutionException if the task cannot be scheduled for execution
java.lang.NullPointerException if the task is null

submit

Added in API level 1
open fun <T : Any!> submit(
    task: Runnable!,
    result: T
): Future<T>!
Parameters
task Runnable!: the task to submit
result T: the result to return
<T> the type of the result
Return
Future<T>! a Future representing pending completion of the task
Exceptions
java.util.concurrent.RejectedExecutionException if the task cannot be scheduled for execution
java.lang.NullPointerException if the task is null

submit

Added in API level 1
open fun <T : Any!> submit(task: Callable<T>!): Future<T>!
Parameters
task Callable<T>!: the task to submit
<T> the type of the task's result
Return
Future<T>! a Future representing pending completion of the task
Exceptions
java.util.concurrent.RejectedExecutionException if the task cannot be scheduled for execution
java.lang.NullPointerException if the task is null

Protected methods

newTaskFor

Added in API level 9
protected open fun <T : Any!> newTaskFor(
    runnable: Runnable!,
    value: T
): RunnableFuture<T>!

Returns a RunnableFuture for the given runnable and default value.

Parameters
runnable Runnable!: the runnable task being wrapped
value T: the default value for the returned future
<T> the type of the given value
Return
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

newTaskFor

Added in API level 9
protected open fun <T : Any!> newTaskFor(callable: Callable<T>!): RunnableFuture<T>!

Returns a RunnableFuture for the given callable task.

Parameters
callable Callable<T>!: the callable task being wrapped
<T> the type of the callable's result
Return
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