APIdia Launch Partner
Top Description Inners Constructors Methods
java.util.concurrent

public final Class Executors

extends Object
Class Inheritance
Static Imports
java.lang.ref.Reference.reachabilityFence

Factory and utility methods for Executor, ExecutorService, ScheduledExecutorService, ThreadFactory, and Callable classes defined in this package. This class supports the following kinds of methods:
Author
Doug Lea
Since
1.5

Nested and Inner Type Summary

Modifier and TypeClass and Description
private static class
Executors.AutoShutdownDelegatedExecutorService

A DelegatedExecutorService that uses a Cleaner to shut down the underlying ExecutorService when the wrapper becomes phantom reachable.

private static class
Executors.DefaultThreadFactory

The default thread factory.

private static class
Executors.DelegatedExecutorService

A wrapper class that exposes only the ExecutorService methods of an ExecutorService implementation.

private static class
Executors.DelegatedScheduledExecutorService

A wrapper class that exposes only the ScheduledExecutorService methods of a ScheduledExecutorService implementation.

private static class
Executors.PrivilegedCallable<T>

A callable that runs under established access control settings.

private static class
Executors.PrivilegedCallableUsingCurrentClassLoader<T>

A callable that runs under established access control settings and current ClassLoader.

private static class
Executors.PrivilegedThreadFactory

Thread factory capturing the current class loader.

private static class
Executors.RunnableAdapter<T>

A callable that runs given task and returns given result.

Constructor Summary

AccessConstructor and Description
private
Executors()

Cannot instantiate.

Method Summary

Modifier and TypeMethod and Description
public static <
the type of the result
T
>
Callable<T>

Returns:

a callable object
callable
(Runnable
the task to run
task
,
T
the result to return
result
)

Returns a Callable object that, when called, runs the given task and returns the given result.

public static Callable<Object>

Returns:

a callable object
callable
(Runnable
the task to run
task
)

Returns a Callable object that, when called, runs the given task and returns null.

public static Callable<Object>

Returns:

a callable object
callable
(final PrivilegedAction<?>
the privileged action to run
action
)

Returns a Callable object that, when called, runs the given privileged action and returns its result.

public static Callable<Object>

Returns:

a callable object
callable
(final PrivilegedExceptionAction<?>
the privileged exception action to run
action
)

Returns a Callable object that, when called, runs the given privileged exception action and returns its result.

public static ThreadFactory

Returns:

a thread factory
defaultThreadFactory
()

Returns a default thread factory used to create new threads.

public static ExecutorService

Returns:

the newly created thread pool
newCachedThreadPool
()

Creates a thread pool that creates new threads as needed, but will reuse previously constructed threads when they are available.

public static ExecutorService

Returns:

the newly created thread pool
newCachedThreadPool
(ThreadFactory
the factory to use when creating new threads
threadFactory
)

Creates a thread pool that creates new threads as needed, but will reuse previously constructed threads when they are available, and uses the provided ThreadFactory to create new threads when needed.

public static ExecutorService

Returns:

the newly created thread pool
newFixedThreadPool
(int
the number of threads in the pool
nThreads
)

Creates a thread pool that reuses a fixed number of threads operating off a shared unbounded queue.

public static ExecutorService

Returns:

the newly created thread pool
newFixedThreadPool
(int
the number of threads in the pool
nThreads
,
ThreadFactory
the factory to use when creating new threads
threadFactory
)

Creates a thread pool that reuses a fixed number of threads operating off a shared unbounded queue, using the provided ThreadFactory to create new threads when needed.

public static ScheduledExecutorService

Returns:

the newly created scheduled thread pool
newScheduledThreadPool
(int
the number of threads to keep in the pool, even if they are idle
corePoolSize
)

Creates a fixed-size thread pool that can schedule commands to run after a given delay, or to execute periodically.

public static ScheduledExecutorService

Returns:

the newly created scheduled thread pool
newScheduledThreadPool
(int
the number of threads to keep in the pool, even if they are idle
corePoolSize
,
ThreadFactory
the factory to use when the executor creates a new thread
threadFactory
)

Creates a fixed-size thread pool that can schedule commands to run after a given delay, or to execute periodically.

public static ExecutorService

Returns:

the newly created single-threaded Executor
newSingleThreadExecutor
()

Creates an Executor that uses a single worker thread operating off an unbounded queue.

public static ExecutorService

Returns:

the newly created single-threaded Executor
newSingleThreadExecutor
(ThreadFactory
the factory to use when creating new threads
threadFactory
)

Creates an Executor that uses a single worker thread operating off an unbounded queue, and uses the provided ThreadFactory to create a new thread when needed.

public static ScheduledExecutorService

Returns:

the newly created scheduled executor
newSingleThreadScheduledExecutor
()

Creates a single-threaded executor that can schedule commands to run after a given delay, or to execute periodically.

public static ScheduledExecutorService

Returns:

the newly created scheduled executor
newSingleThreadScheduledExecutor
(ThreadFactory
the factory to use when creating new threads
threadFactory
)

Creates a single-threaded executor that can schedule commands to run after a given delay, or to execute periodically.

public static ExecutorService

Returns:

a new executor that creates a new Thread for each task
newThreadPerTaskExecutor
(ThreadFactory
the factory to use when creating new threads
threadFactory
)

Creates an Executor that starts a new Thread for each task.

public static ExecutorService

Returns:

a new executor that creates a new virtual Thread for each task
newVirtualThreadPerTaskExecutor
()

Creates an Executor that starts a new virtual Thread for each task.

public static ExecutorService

Returns:

the newly created thread pool
newWorkStealingPool
(int
the targeted parallelism level
parallelism
)

Creates a thread pool that maintains enough threads to support the given parallelism level, and may use multiple queues to reduce contention.

public static ExecutorService

Returns:

the newly created thread pool
newWorkStealingPool
()

Creates a work-stealing thread pool using the number of available processors as its target parallelism level.

public static <
the type of the callable's result
T
>
Callable<T>

Returns:

a callable object
privilegedCallable
(Callable<T>
the underlying task
callable
)
Deprecated for removal since 17. This method originally returned a Callable object that when called, executed the given callable under the current access control context.

Returns a Callable object that will, when called, execute the given callable and return its result.

public static <
the type of the callable's result
T
>
Callable<T>

Returns:

a callable object
privilegedCallableUsingCurrentClassLoader
(Callable<T>
the underlying task
callable
)
Deprecated for removal since 17. This method originally returned a Callable object that when called, executed the given callable under the current access control context, with the current context class loader as the context class loader.

Returns a Callable object that will, when called, execute the given callable with the current context class loader as the context class loader.

public static ThreadFactory

Returns:

a thread factory
privilegedThreadFactory
()
Deprecated for removal since 17. This method originally returned a thread factory that created new threads that had the same access control context as the current thread.

Returns a thread factory used to create new threads that have the current context class loader as the context class loader.

public static ExecutorService

Returns:

an ExecutorService instance
unconfigurableExecutorService
(ExecutorService
the underlying implementation
executor
)

Returns an object that delegates all defined ExecutorService methods to the given executor, but not any other methods that might otherwise be accessible using casts.

public static ScheduledExecutorService

Returns:

a ScheduledExecutorService instance
unconfigurableScheduledExecutorService
(ScheduledExecutorService
the underlying implementation
executor
)

Returns an object that delegates all defined ScheduledExecutorService methods to the given executor, but not any other methods that might otherwise be accessible using casts.

Inherited from java.lang.Object:
cloneequalsfinalizegetClasshashCodenotifynotifyAlltoStringwaitwaitwait