java.util.concurrent
| |
java.util.concurrent
|
java.util.concurrent
|
ForkJoinPoolpublic ForkJoinPool(int parallelism, ForkJoinPool.ForkJoinWorkerThreadFactory factory)
|
ForkJoinPoolpublic ForkJoinPool(ForkJoinPool.ForkJoinWorkerThreadFactory factory)
|
getMaximumPoolSizepublic int getMaximumPoolSize()
|
managedBlockpublic static void managedBlock(ForkJoinPool.ManagedBlocker blocker, boolean maintainParallelism) throws InterruptedException
|
setAsyncModepublic boolean setAsyncMode(boolean async)
|
setMaximumPoolSizepublic void setMaximumPoolSize(int newMax)
|
setParallelismpublic void setParallelism(int parallelism)
|
setUncaughtExceptionHandlerpublic Thread.UncaughtExceptionHandler setUncaughtExceptionHandler(Thread.UncaughtExceptionHandler h)
|
java.util.concurrent
|
Call from non-fork/join clients | Call from within fork/join computations | |
Arange async execution | execute(ForkJoinTask) | ForkJoinTask.fork() |
Await and obtain result | invoke(ForkJoinTask) | ForkJoinTask.invoke() |
Arrange exec and obtain Future | submit(ForkJoinTask) | ForkJoinTask.fork() are Futures) |
A ForkJoinPool
is constructed with a given target parallelism level; by default, equal to the number of available processors. Unless configured otherwise via
setMaintainsParallelism(boolean)
, the pool attempts to maintain this number of active (or available) threads by dynamically adding, suspending, or resuming internal worker threads, even if some tasks are stalled waiting to join others. However, no such adjustments are performed in the face of blocked IO or other unmanaged synchronization. The nested
ForkJoinPool.ManagedBlocker
interface enables extension of the kinds of synchronization accommodated. The target parallelism level may also be changed dynamically (
setParallelism(int)
). The total number of threads may be limited using method
setMaximumPoolSize(int)
, in which case it may become possible for the activities of a pool to stall due to the lack of available threads to process new tasks.
In addition to execution and lifecycle control methods, this class provides status check methods (for example
getStealCount()
) that are intended to aid in developing, tuning, and monitoring fork/join applications. Also, method
toString()
returns indications of pool state in a convenient form for informal monitoring.
Sample Usage. Normally a single ForkJoinPool is used for all parallel task execution in a program or subsystem. Otherwise, use would not usually outweigh the construction and bookkeeping overhead of creating a large set of threads. For example, a common pool could be used for the SortTasks illustrated in RecursiveAction . Because ForkJoinPool uses threads in daemon mode, there is typically no need to explicitly shutdown() such a pool upon program exit.
static final ForkJoinPool mainPool = new ForkJoinPool(); ... public void sort(long[] array) { mainPool.invoke(new SortTask(array, 0, array.length)); }
Implementation notes : This implementation restricts the maximum number of running threads to 32767. Attempts to create pools with greater than the maximum number result in IllegalArgumentException .
This implementation rejects submitted tasks (that is, by throwing
RejectedExecutionException
) only when the pool is shut down or internal resources have been exhausted. down.
java.lang.Object java.util.concurrent.AbstractExecutorService java.util.concurrent.ForkJoinPool
public class ForkJoinPool extends AbstractExecutorService
An ExecutorService
for running ForkJoinTask
s.
A ForkJoinPool
provides the entry point for submissions
from non-ForkJoinTask
s, as well as management and
monitoring operations.
A ForkJoinPool
differs from other kinds of ExecutorService
mainly by virtue of employing
work-stealing: all threads in the pool attempt to find and
execute subtasks created by other active tasks (eventually blocking
waiting for work if none exist). This enables efficient processing
when most tasks spawn other subtasks (as do most ForkJoinTask
s). A ForkJoinPool
may also be used for mixed
execution of some plain Runnable
- or Callable
-
based activities along with ForkJoinTask
s. When setting
async mode, a ForkJoinPool
may
also be appropriate for use with fine-grained tasks of any form
that are never joined. Otherwise, other ExecutorService
implementations are typically more appropriate choices.
A ForkJoinPool
is constructed with a given target
parallelism level; by default, equal to the number of available
processors. Unless configured otherwise via setMaintainsParallelism(boolean)
, the pool attempts to maintain this
number of active (or available) threads by dynamically adding,
suspending, or resuming internal worker threads, even if some tasks
are stalled waiting to join others. However, no such adjustments
are performed in the face of blocked IO or other unmanaged
synchronization. The nested ForkJoinPool.ManagedBlocker
interface
enables extension of the kinds of synchronization accommodated.
The target parallelism level may also be changed dynamically
(setParallelism(int)
). The total number of threads may be
limited using method setMaximumPoolSize(int)
, in which case it
may become possible for the activities of a pool to stall due to
the lack of available threads to process new tasks.
In addition to execution and lifecycle control methods, this
class provides status check methods (for example
getStealCount()
) that are intended to aid in developing,
tuning, and monitoring fork/join applications. Also, method
toString()
returns indications of pool state in a
convenient form for informal monitoring.
Sample Usage. Normally a single ForkJoinPool
is
used for all parallel task execution in a program or subsystem.
Otherwise, use would not usually outweigh the construction and
bookkeeping overhead of creating a large set of threads. For
example, a common pool could be used for the SortTasks
illustrated in RecursiveAction
. Because ForkJoinPool
uses threads in daemon mode, there is typically no need to explicitly shutdown()
such a pool upon program exit.
static final ForkJoinPool mainPool = new ForkJoinPool(); ... public void sort(long[] array) { mainPool.invoke(new SortTask(array, 0, array.length)); }
Implementation notes: This implementation restricts the
maximum number of running threads to 32767. Attempts to create
pools with greater than the maximum number result in
IllegalArgumentException
.
This implementation rejects submitted tasks (that is, by throwing
RejectedExecutionException
) only when the pool is shut down.
java.lang.Object java.util.concurrent.AbstractExecutorService java.util.concurrent.ForkJoinPool
public class ForkJoinPool extends AbstractExecutorService
An ExecutorService
for running ForkJoinTask
s.
A ForkJoinPool
provides the entry point for submissions
from non-ForkJoinTask
clients, as well as management and
monitoring operations.
A ForkJoinPool
differs from other kinds of ExecutorService
mainly by virtue of employing
work-stealing: all threads in the pool attempt to find and
execute subtasks created by other active tasks (eventually blocking
waiting for work if none exist). This enables efficient processing
when most tasks spawn other subtasks (as do most ForkJoinTask
s). When setting asyncMode to true in
constructors, ForkJoinPool
s may also be appropriate for use
with event-style tasks that are never joined.
A ForkJoinPool
is constructed with a given target
parallelism level; by default, equal to the number of available
processors. The pool attempts to maintain enough active (or
available) threads by dynamically adding, suspending, or resuming
internal worker threads, even if some tasks are stalled waiting to
join others. However, no such adjustments are guaranteed in the
face of blocked IO or other unmanaged synchronization. The nested
ForkJoinPool.ManagedBlocker
interface enables extension of the kinds of
synchronization accommodated.
In addition to execution and lifecycle control methods, this
class provides status check methods (for example
getStealCount()
) that are intended to aid in developing,
tuning, and monitoring fork/join applications. Also, method
toString()
returns indications of pool state in a
convenient form for informal monitoring.
As is the case with other ExecutorServices, there are three
main task execution methods summarized in the following
table. These are designed to be used by clients not already engaged
in fork/join computations in the current pool. The main forms of
these methods accept instances of ForkJoinTask
, but
overloaded forms also allow mixed execution of plain Runnable
- or Callable
- based activities as well. However,
tasks that are already executing in a pool should normally
NOT use these pool execution methods, but instead use the
within-computation forms listed in the table.
Call from non-fork/join clients | Call from within fork/join computations | |
Arange async execution | execute(ForkJoinTask) |
ForkJoinTask.fork() |
Await and obtain result | invoke(ForkJoinTask) |
ForkJoinTask.invoke() |
Arrange exec and obtain Future | submit(ForkJoinTask) |
ForkJoinTask.fork() (ForkJoinTasks are Futures) |
Sample Usage. Normally a single ForkJoinPool
is
used for all parallel task execution in a program or subsystem.
Otherwise, use would not usually outweigh the construction and
bookkeeping overhead of creating a large set of threads. For
example, a common pool could be used for the SortTasks
illustrated in RecursiveAction
. Because ForkJoinPool
uses threads in daemon mode, there is typically no need to explicitly shutdown()
such a pool upon program exit.
static final ForkJoinPool mainPool = new ForkJoinPool(); ... public void sort(long[] array) { mainPool.invoke(new SortTask(array, 0, array.length)); }
Implementation notes: This implementation restricts the
maximum number of running threads to 32767. Attempts to create
pools with greater than the maximum number result in
IllegalArgumentException
.
This implementation rejects submitted tasks (that is, by throwing
RejectedExecutionException
) only when the pool is shut down
or internal resources have been exhausted.
ForkJoinPoolpublic ForkJoinPool()
| |
ForkJoinPoolpublic ForkJoinPool()
|
ForkJoinPoolpublic ForkJoinPool()
|
ForkJoinPoolpublic ForkJoinPool(int parallelism)
| |
ForkJoinPoolpublic ForkJoinPool(int parallelism)
|
ForkJoinPoolpublic ForkJoinPool(int parallelism)
|
ForkJoinPoolpublic ForkJoinPool(int parallelism, ForkJoinPool.ForkJoinWorkerThreadFactory factory, Thread.UncaughtExceptionHandler handler, boolean asyncMode)
|
getAsyncModepublic boolean getAsyncMode()
| |
getAsyncModepublic boolean getAsyncMode()
|
getAsyncModepublic boolean getAsyncMode()
|
managedBlockpublic static void managedBlock(ForkJoinPool.ManagedBlocker blocker) throws InterruptedException
|
helpJoinpublic final V helpJoin()
|
quietlyHelpJoinpublic final void quietlyHelpJoin()
|
java.util.concurrent
| |
java.util.concurrent
|
java.util.concurrent
|