| Modifier and Type | Class and Description |
|---|---|
| private static class | ThreadPerTaskExecutor.
An object for use by invokeAny to hold the result of the first task to complete normally and/or the first exception thrown. |
| private static class | ThreadPerTaskExecutor.
Runs a task and notifies the executor when it completes. |
| private static class |
| Modifier and Type | Field and Description |
|---|---|
| private final ThreadFactory | |
| private static final JavaLangAccess | |
| private volatile Object | |
| private static final int | |
| private static final int | |
| private static final VarHandle | |
| private volatile int | |
| private static final int | |
| private final CountDownLatch | |
| private final Set |
| Access | Constructor and Description |
|---|---|
| private |
| Modifier and Type | Method and Description |
|---|---|
| public boolean | awaitTermination(long timeout, TimeUnit unit)
Implements java. Blocks until all tasks have completed execution after a shutdown request, or the timeout occurs, or the current thread is interrupted, whichever happens first. |
| private void | |
| private <T> void | |
| public void | close()
Overrides default java. Initiates an orderly shutdown in which previously submitted tasks are executed, but no new tasks will be accepted. |
| pack-priv static ThreadPerTaskExecutor | create(ThreadFactory factory)
Creates a thread-per-task executor that creates threads using the given factory. |
| private void | |
| public void | execute(Runnable task)
Implements java. Executes the given command at some time in the future. |
| public <T> List | invokeAll(Collection<? extends Callable<T>> tasks)
Implements java. Executes the given tasks, returning a list of Futures holding their status and results when all complete. |
| public <T> List | invokeAll(Collection<? extends Callable<T>> tasks, long timeout, TimeUnit unit)
Implements java. Executes the given tasks, returning a list of Futures holding their status and results when all complete or the timeout expires, whichever happens first. |
| public <T> T | invokeAny(Collection<? extends Callable<T>> tasks)
Implements java. Executes the given tasks, returning the result of one that has completed successfully (i.e., without throwing an exception), if any do. |
| public <T> T | invokeAny(Collection<? extends Callable<T>> tasks, long timeout, TimeUnit unit)
Implements java. 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. |
| private <T> T | |
| public boolean | isShutdown()
Implements java. Returns |
| public boolean | isTerminated()
Implements java. Returns |
| private Thread | |
| public void | shutdown()
Implements java. Initiates an orderly shutdown in which previously submitted tasks are executed, but no new tasks will be accepted. |
| public List | shutdownNow()
Implements java. Attempts to stop all actively executing tasks, halts the processing of waiting tasks, and returns a list of the tasks that were awaiting execution. |
| private void | |
| private Thread | |
| public <T> Future | submit(Callable<T> task)
Implements java. Submits a value-returning task for execution and returns a Future representing the pending results of the task. |
| public Future | submit(Runnable task)
Implements java. Submits a Runnable task for execution and returns a Future representing that task. |
| public <T> Future | submit(Runnable task, T result)
Implements java. Submits a Runnable task for execution and returns a Future representing that task. |
| private void | taskComplete(Thread thread)
Notify the executor that the task executed by the given thread is complete. |
| public long | threadCount()
Overrides jdk. Return a count of the number of threads in this container. |
| public Stream | threads()
Implements abstract jdk. Returns a stream of the live threads in this container. |
| private void | |
| private void |
| factory | back to summary |
|---|---|
| private final ThreadFactory factory | |
| JLA | back to summary |
|---|---|
| private static final JavaLangAccess JLA | |
| key | back to summary |
|---|---|
| private volatile Object key | |
| RUNNING | back to summary |
|---|---|
| private static final int RUNNING | |
| SHUTDOWN | back to summary |
|---|---|
| private static final int SHUTDOWN | |
| STATE | back to summary |
|---|---|
| private static final VarHandle STATE | |
| state | back to summary |
|---|---|
| private volatile int state | |
| TERMINATED | back to summary |
|---|---|
| private static final int TERMINATED | |
| terminationSignal | back to summary |
|---|---|
| private final CountDownLatch terminationSignal | |
| threads | back to summary |
|---|---|
| private final Set<Thread> threads | |
| ThreadPerTaskExecutor | back to summary |
|---|---|
| private ThreadPerTaskExecutor(ThreadFactory factory) | |
| awaitTermination | back to summary |
|---|---|
| public boolean awaitTermination(long timeout, TimeUnit unit) throws InterruptedException Implements java. Doc from java. Blocks until all tasks have completed execution after a shutdown request, or the timeout occurs, or the current thread is interrupted, whichever happens first.
| |
| awaitTermination | back to summary |
|---|---|
| private void awaitTermination() Waits for executor to terminate. | |
| cancelAll | back to summary |
|---|---|
| private <T> void cancelAll(List<Future<T>> futures, int j) | |
| close | back to summary |
|---|---|
| public void close() Overrides default java. Doc from java. 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. If interrupted while waiting, this method stops all executing tasks as
if by invoking If already terminated, invoking this method has no effect.
| |
| create | back to summary |
|---|---|
| pack-priv static ThreadPerTaskExecutor create(ThreadFactory factory) Creates a thread-per-task executor that creates threads using the given factory. | |
| ensureNotShutdown | back to summary |
|---|---|
| private void ensureNotShutdown() Throws RejectedExecutionException if the executor has been shutdown. | |
| execute | back to summary |
|---|---|
| public void execute(Runnable task) Implements java. Doc from java. Executes the given command at some time in the future. The command
may execute in a new thread, in a pooled thread, or in the calling
thread, at the discretion of the
| |
| invokeAll | back to summary |
|---|---|
| public <T> List Implements java. Doc from java. Executes the given tasks, returning a list of Futures holding
their status and results when all complete.
| |
| invokeAll | back to summary |
|---|---|
| public <T> List Implements java. Doc from java. Executes the given tasks, returning a list of Futures holding
their status and results
when all complete or the timeout expires, whichever happens first.
| |
| invokeAny | back to summary |
|---|---|
| public <T> T invokeAny(Collection<? extends Callable<T>> tasks) throws InterruptedException, ExecutionException Implements java. Doc from java. 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.
| |
| invokeAny | back to summary |
|---|---|
| public <T> T invokeAny(Collection<? extends Callable<T>> tasks, long timeout, TimeUnit unit) throws InterruptedException, ExecutionException, TimeoutException Implements java. Doc from java. 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.
| |
| invokeAny | back to summary |
|---|---|
| private <T> T invokeAny(Collection<? extends Callable<T>> tasks, boolean timed, long timeout, TimeUnit unit) throws InterruptedException, ExecutionException, TimeoutException | |
| isShutdown | back to summary |
|---|---|
| public boolean isShutdown() Implements java. Doc from java. Returns
| |
| isTerminated | back to summary |
|---|---|
| public boolean isTerminated() Implements java. Doc from java. Returns
| |
| newThread | back to summary |
|---|---|
| private Thread newThread(Runnable task) Creates a thread to run the given task. | |
| shutdown | back to summary |
|---|---|
| public void shutdown() Implements java. Doc from java. 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. This method does not wait for previously submitted tasks to
complete execution. Use
| |
| shutdownNow | back to summary |
|---|---|
| public List Implements java. Doc from java. Attempts to stop all actively executing tasks, halts the processing of waiting tasks, and returns a list of the tasks that were awaiting execution. This method does not wait for actively executing tasks to
terminate. Use There are no guarantees beyond best-effort attempts to stop
processing actively executing tasks. For example, typical
implementations will cancel via
| |
| start | back to summary |
|---|---|
| private void start(Thread thread) Adds a thread to the set of threads and starts it. | |
| start | back to summary |
|---|---|
| private Thread start(Runnable task) Starts a thread to execute the given task. | |
| submit | back to summary |
|---|---|
| public <T> Future Implements java. Doc from java. Submits a value-returning task for execution and returns a
Future representing the pending results of the task. The
Future's
If you would like to immediately block waiting
for a task, you can use constructions of the form
Note The
| |
| submit | back to summary |
|---|---|
| public Future Implements java. Doc from java. Submits a Runnable task for execution and returns a Future
representing that task. The Future's
| |
| submit | back to summary |
|---|---|
| public <T> Future Implements java. Doc from java. Submits a Runnable task for execution and returns a Future
representing that task. The Future's
| |
| taskComplete | back to summary |
|---|---|
| private void taskComplete(Thread thread) Notify the executor that the task executed by the given thread is complete. If the executor has been shutdown then this method will attempt to terminate the executor. | |
| threadCount | back to summary |
|---|---|
| public long threadCount() Overrides jdk. Doc from jdk. Return a count of the number of threads in this container.
| |
| threads | back to summary |
|---|---|
| public Stream Implements abstract jdk. Doc from jdk. Returns a stream of the live threads in this container.
| |
| tryShutdownAndTerminate | back to summary |
|---|---|
| private void tryShutdownAndTerminate(boolean interruptThreads) Attempts to shutdown and terminate the executor. If interruptThreads is true then all running threads are interrupted. | |
| tryTerminate | back to summary |
|---|---|
| private void tryTerminate() Attempts to terminate if already shutdown. If this method terminates the executor then it signals any threads that are waiting for termination. | |
| Modifier and Type | Field and Description |
|---|---|
| private static final VarHandle | |
| private volatile Throwable | |
| private static final VarHandle | |
| private volatile int | |
| private static final Object | |
| private final Thread | |
| private static final VarHandle | |
| private volatile T |
| Access | Constructor and Description |
|---|---|
| pack-priv |
| Modifier and Type | Method and Description |
|---|---|
| pack-priv void | |
| pack-priv void | |
| pack-priv int | exceptionCount()
Returns the number of tasks that terminated with an exception before a task completed normally. |
| pack-priv Throwable | |
| pack-priv T |
| EXCEPTION | back to summary |
|---|---|
| private static final VarHandle EXCEPTION | |
| exception | back to summary |
|---|---|
| private volatile Throwable exception | |
| EXCEPTION_COUNT | back to summary |
|---|---|
| private static final VarHandle EXCEPTION_COUNT | |
| exceptionCount | back to summary |
|---|---|
| private volatile int exceptionCount | |
| NULL | back to summary |
|---|---|
| private static final Object NULL | |
| owner | back to summary |
|---|---|
| private final Thread owner | |
| RESULT | back to summary |
|---|---|
| private static final VarHandle RESULT | |
| result | back to summary |
|---|---|
| private volatile T result | |
| AnyResultHolder | back to summary |
|---|---|
| pack-priv AnyResultHolder(Thread owner) | |
| complete | back to summary |
|---|---|
| pack-priv void complete(T value) Complete with the given result if not already completed. The winner unparks the owner thread. | |
| completeExceptionally | back to summary |
|---|---|
| pack-priv void completeExceptionally(Throwable exc) Complete with the given exception. If the result is not already set then it unparks the owner thread. | |
| exceptionCount | back to summary |
|---|---|
| pack-priv int exceptionCount() Returns the number of tasks that terminated with an exception before a task completed normally. | |
| firstException | back to summary |
|---|---|
| pack-priv Throwable firstException() Returns the first exception thrown if recorded by this object. API Note The result() method should be used to test if there is a result before invoking the exception method. | |
| result | back to summary |
|---|---|
| pack-priv T result() Returns non-null if a task completed successfully. The result is NULL if completed with null. | |
| Modifier and Type | Field and Description |
|---|---|
| pack-priv final ThreadPerTaskExecutor | |
| pack-priv final Runnable |
| Access | Constructor and Description |
|---|---|
| pack-priv |
| Modifier and Type | Method and Description |
|---|---|
| public void |
| executor | back to summary |
|---|---|
| pack-priv final ThreadPerTaskExecutor executor | |
| task | back to summary |
|---|---|
| pack-priv final Runnable task | |
| TaskRunner | back to summary |
|---|---|
| pack-priv TaskRunner(ThreadPerTaskExecutor executor, Runnable task) | |
| run | back to summary |
|---|---|
| public void run() Implements java. Doc from java. Runs this operation.
| |
| Modifier and Type | Field and Description |
|---|---|
| pack-priv final ThreadPerTaskExecutor | |
| pack-priv final Thread |
| Access | Constructor and Description |
|---|---|
| pack-priv |
| Modifier and Type | Method and Description |
|---|---|
| public void | run()
Overrides java. Implements java. Runs this operation. |
| pack-priv Thread |
| executor | back to summary |
|---|---|
| pack-priv final ThreadPerTaskExecutor executor | |
| thread | back to summary |
|---|---|
| pack-priv final Thread thread | |
| ThreadBoundFuture | back to summary |
|---|---|
| pack-priv ThreadBoundFuture(ThreadPerTaskExecutor executor, Callable<T> task) | |
| run | back to summary |
|---|---|
| public void run() Overrides java. Implements java. Doc from java. Runs this operation.
| |
| thread | back to summary |
|---|---|
| pack-priv Thread thread() | |