Top Description Inners Constructors Methods
com.google.common.util.concurrent

public final Class MoreExecutors

extends Object
Class Inheritance
Annotations
@GwtCompatible
emulated:true
@ElementTypesAreNonnullByDefault
Static Imports
com.google.common.base.Preconditions.checkArgument, .Preconditions.checkNotNull, com.google.common.util.concurrent.Internal.toNanosSaturated, java.util.Objects.requireNonNull

Factory and utility methods for java.util.concurrent.Executor, ExecutorService, and java.util.concurrent.ThreadFactory.
Authors
Eric Fellheimer, Kyle Littlefield, Justin Mahoney
Since
3.0

Nested and Inner Type Summary

Modifier and TypeClass and Description
pack-priv static class
MoreExecutors.Application

Represents the current application to register shutdown hooks.

private static class
private static class
private static class

Constructor Summary

AccessConstructor and Description
private

Method Summary

Modifier and TypeMethod and Description
public static void
addDelayedShutdownHook(ExecutorService
ExecutorService which uses daemon threads
service
,
Duration
how long to wait for the executor to finish before terminating the JVM
terminationTimeout
)

Add a shutdown hook to wait for thread completion in the given service.

public static void
addDelayedShutdownHook(ExecutorService
ExecutorService which uses daemon threads
service
,
long
how long to wait for the executor to finish before terminating the JVM
terminationTimeout
,
TimeUnit
unit of time for the time parameter
timeUnit
)

Add a shutdown hook to wait for thread completion in the given service.

public static Executor
directExecutor()

Returns an Executor that runs each task in the thread that invokes execute, as in ThreadPoolExecutor.CallerRunsPolicy.

public static ExecutorService

Returns:

an unmodifiable version of the input which will not hang the JVM
getExitingExecutorService
(ThreadPoolExecutor
the executor to modify to make sure it exits when the application is finished
executor
,
Duration
how long to wait for the executor to finish before terminating the JVM
terminationTimeout
)

Converts the given ThreadPoolExecutor into an ExecutorService that exits when the application is complete.

public static ExecutorService

Returns:

an unmodifiable version of the input which will not hang the JVM
getExitingExecutorService
(ThreadPoolExecutor
the executor to modify to make sure it exits when the application is finished
executor
,
long
how long to wait for the executor to finish before terminating the JVM
terminationTimeout
,
TimeUnit
unit of time for the time parameter
timeUnit
)

Converts the given ThreadPoolExecutor into an ExecutorService that exits when the application is complete.

public static ExecutorService

Returns:

an unmodifiable version of the input which will not hang the JVM
getExitingExecutorService
(ThreadPoolExecutor
the executor to modify to make sure it exits when the application is finished
executor
)

Converts the given ThreadPoolExecutor into an ExecutorService that exits when the application is complete.

public static ScheduledExecutorService

Returns:

an unmodifiable version of the input which will not hang the JVM
getExitingScheduledExecutorService
(ScheduledThreadPoolExecutor
the executor to modify to make sure it exits when the application is finished
executor
,
Duration
how long to wait for the executor to finish before terminating the JVM
terminationTimeout
)

Converts the given ScheduledThreadPoolExecutor into a ScheduledExecutorService that exits when the application is complete.

public static ScheduledExecutorService

Returns:

an unmodifiable version of the input which will not hang the JVM
getExitingScheduledExecutorService
(ScheduledThreadPoolExecutor
the executor to modify to make sure it exits when the application is finished
executor
,
long
how long to wait for the executor to finish before terminating the JVM
terminationTimeout
,
TimeUnit
unit of time for the time parameter
timeUnit
)

Converts the given ScheduledThreadPoolExecutor into a ScheduledExecutorService that exits when the application is complete.

public static ScheduledExecutorService

Returns:

an unmodifiable version of the input which will not hang the JVM
getExitingScheduledExecutorService
(ScheduledThreadPoolExecutor
the executor to modify to make sure it exits when the application is finished
executor
)

Converts the given ScheduledThreadPoolExecutor into a ScheduledExecutorService that exits when the application is complete.

pack-priv static <T extends @Nullable Object> T
invokeAnyImpl(ListeningExecutorService executorService, Collection<? extends Callable<T>> tasks, boolean timed, Duration timeout)

An implementation of ExecutorService#invokeAny for ListeningExecutorService implementations.

pack-priv static <T extends @Nullable Object> T
invokeAnyImpl(ListeningExecutorService executorService, Collection<? extends Callable<T>> tasks, boolean timed, long timeout, TimeUnit unit)

An implementation of ExecutorService#invokeAny for ListeningExecutorService implementations.

private static boolean
public static ListeningExecutorService
listeningDecorator(ExecutorService delegate)

Creates an ExecutorService whose submit and invokeAll methods submit ListenableFutureTask instances to the given delegate executor.

public static ListeningScheduledExecutorService
listeningDecorator(ScheduledExecutorService delegate)

Creates a ScheduledExecutorService whose submit and invokeAll methods submit ListenableFutureTask instances to the given delegate executor.

public static ListeningExecutorService
newDirectExecutorService()

Creates an executor service that runs each task in the thread that invokes execute/submit, as in ThreadPoolExecutor.CallerRunsPolicy.

public static Executor
newSequentialExecutor(Executor delegate)

Returns an Executor that runs each task executed sequentially, such that no two tasks are running concurrently.

pack-priv static Thread
newThread(String name, Runnable runnable)

Creates a thread using platformThreadFactory, and sets its name to name unless changing the name is forbidden by the security manager.

public static ThreadFactory
platformThreadFactory()

Returns a default thread factory used to create new threads.

pack-priv static Executor
rejectionPropagatingExecutor(final Executor delegate, final AbstractFuture<?> future)

Returns an Executor that will propagate RejectedExecutionException from the delegate executor to the given future.

pack-priv static Executor
renamingDecorator(final Executor
The executor to decorate
executor
,
final Supplier<String>
The source of names for each task
nameSupplier
)

Creates an Executor that renames the threads that its tasks run in.

The names are retrieved from the nameSupplier on the thread that is being renamed right before each task is run.

pack-priv static ExecutorService
renamingDecorator(final ExecutorService
The executor to decorate
service
,
final Supplier<String>
The source of names for each task
nameSupplier
)

Creates an ExecutorService that renames the threads that its tasks run in.

The names are retrieved from the nameSupplier on the thread that is being renamed right before each task is run.

pack-priv static ScheduledExecutorService
renamingDecorator(final ScheduledExecutorService
The executor to decorate
service
,
final Supplier<String>
The source of names for each task
nameSupplier
)

Creates a ScheduledExecutorService that renames the threads that its tasks run in.

The names are retrieved from the nameSupplier on the thread that is being renamed right before each task is run.

public static boolean

Returns:

true if the ExecutorService was terminated successfully, false if the call timed out or was interrupted
shutdownAndAwaitTermination
(ExecutorService
the ExecutorService to shut down
service
,
Duration
the maximum time to wait for the ExecutorService to terminate
timeout
)

Shuts down the given executor service gradually, first disabling new submissions and later, if necessary, cancelling remaining tasks.

public static boolean

Returns:

true if the ExecutorService was terminated successfully, false if the call timed out or was interrupted
shutdownAndAwaitTermination
(ExecutorService
the ExecutorService to shut down
service
,
long
the maximum time to wait for the ExecutorService to terminate
timeout
,
TimeUnit
the time unit of the timeout argument
unit
)

Shuts down the given executor service gradually, first disabling new submissions and later, if necessary, cancelling remaining tasks.

private static <T extends @Nullable Object> ListenableFuture<T>
submitAndAddQueueListener(ListeningExecutorService executorService, Callable<T> task, final BlockingQueue<Future<T>> queue)

Submits the task and adds a listener that adds the future to queue when it completes.

private static void
Inherited from java.lang.Object:
cloneequalsfinalizegetClasshashCodenotifynotifyAlltoStringwaitwaitwait