AbstractExecutorService

port of 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:

 `public class CustomThreadPoolExecutor extends ThreadPoolExecutor {

static class CustomTask implements RunnableFuture { ... }

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

Since

1.5

Author

Doug Lea

Inheritors

Constructors

Link copied to clipboard
constructor()

Types

Link copied to clipboard
object Companion

Properties

Link copied to clipboard
abstract val isShutdown: Boolean

Returns true if this executor has been shut down.

Link copied to clipboard
abstract val isTerminated: Boolean

Returns true if all tasks have completed following shut down. Note that isTerminated is never true unless either shutdown or shutdownNow was called first.

Functions

Link copied to clipboard
abstract suspend fun awaitTermination(timeout: Long, unit: TimeUnit): Boolean

Blocks until all tasks have completed execution after a shutdown request, or the timeout occurs, or the current thread is interrupted, whichever happens first.

Link copied to clipboard
open override fun close()

Initiates an orderly shutdown in which previously submitted tasks are executed, but no new tasks will be accepted. This method waits until all tasks have completed execution and the executor has terminated.

Link copied to clipboard
abstract fun execute(command: Runnable)
Link copied to clipboard
open suspend override fun <T> invokeAll(tasks: MutableCollection<Callable<T>>): MutableList<Future<T>>
open suspend override fun <T> invokeAll(tasks: MutableCollection<Callable<T>>, timeout: Long, unit: TimeUnit): MutableList<Future<T>>
Link copied to clipboard
open suspend override fun <T> invokeAny(tasks: MutableCollection<Callable<T>>): T?
open suspend override fun <T> invokeAny(tasks: MutableCollection<Callable<T>>, timeout: Long, unit: TimeUnit): T
Link copied to clipboard
fun <T> newTaskFor(callable: Callable<T>): RunnableFuture<T>

Returns a RunnableFuture for the given callable task.

fun <T> newTaskFor(runnable: Runnable, value: T?): RunnableFuture<T>

Returns a RunnableFuture for the given runnable and default value.

Link copied to clipboard
abstract fun 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.

Link copied to clipboard
abstract suspend fun shutdownNow(): MutableList<Runnable>

Attempts to stop all actively executing tasks, halts the processing of waiting tasks, and returns a list of the tasks that were awaiting execution.

Link copied to clipboard
open override fun submit(task: Runnable): Future<*>
open override fun <T> submit(task: Callable<T>): Future<T>
open override fun <T> submit(task: Runnable, result: T): Future<T>