public final class ForkJoinContext extends ConcurrentContext
ConcurrentContext
of the Javolution project, this class
allows you to share a common ForkJoinPool
for the GA and the rest of
your application.
The following example shows how to use the ForkJoinContext
directly:
public class Main {
public static void main(final String[] args) {
final int nthreads = 10;
// Create a java ForkJoinPool and initialize the ForkJoinContext.
final ForkJoinPool pool = new ForkJoinPool(nthreads);
ForkJoinContext.setForkJoinPool(pool);
// Set the concurrence context to use by the javolution context.
ConcurentContext.setContext(ForkJoinContext.class);
// Execute some task concurrently.
ConcurentContext.enter()
try {
ConcurrentContext.execute(...);
ConcurrentContext.execute(...);
} finally {
ConcurrentContext.exit();
}
}
}
ForkJoinContext
allows the
Concurrency
class.Concurrency
,
Serialized FormDEFAULT, MAXIMUM_CONCURRENCY
Modifier and Type | Method and Description |
---|---|
protected void |
enterAction() |
protected void |
executeAction(Runnable logic) |
protected void |
exitAction() |
static ForkJoinPool |
getForkJoinPool()
Return the current fork-join-pool used by this context.
|
static boolean |
setForkJoinPool(ForkJoinPool pool)
Set the fork-join-pool used by this context.
|
static boolean |
setForkkJoinPool(ForkJoinPool pool)
Deprecated.
Fixing typo, use
setForkJoinPool(ForkJoinPool)
instead. |
enter, execute, exit, getConcurrency, setConcurrency
enter, enter, exit, getCurrent, getOuter, getOwner, setCurrent, toString
@Deprecated public static boolean setForkkJoinPool(ForkJoinPool pool)
setForkJoinPool(ForkJoinPool)
instead.setForkJoinPool(ForkJoinPool)
public static boolean setForkJoinPool(ForkJoinPool pool)
ForkJoinPool
. Before the context can be
used a ForkJoinPool
must be set.pool
- the fork-join-pool to use.true
if the given pool has been set, false
otherwise.NullPointerException
- if the pool is null
.public static ForkJoinPool getForkJoinPool()
null
if not set jet.protected void enterAction()
enterAction
in class Context
protected void executeAction(Runnable logic)
executeAction
in class ConcurrentContext
protected void exitAction()
exitAction
in class Context
© 2007-2014 Franz Wilhelmstötter (2014-03-07 19:35)