Package fj
Class FJ
java.lang.Object
fj.FJ
- Author:
- Dennis Cosgrove
-
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionstatic <T> Future<T>
fork
(TaskSupplier<T> task) Indicates that work defined by a value returning task can be left behind for another idle thread to possibly steal and execute.static <R> Future<R>[]
fork_loop
(int min, int maxExclusive, TaskIntFunction<R> intFunction) Forks a value returning task for each index in the range [min, maxExclusive).fork_loop
(Iterable<T> iterable, TaskFunction<T, R> function) Forks a value returning task for each element in the specified Iterable.static <T,
R> Future<R>[] fork_loop
(T[] array, TaskFunction<T, R> function) Forks a value returning task for each item in the specified array.fork_loop_with_index
(Iterable<T> iterable, TaskFunctionWithIndex<T, R> functionWithIndex) Forks a value returning task for each item in the specified iterable.static <T,
R> Future<R>[] fork_loop_with_index
(T[] array, TaskFunctionWithIndex<T, R> functionWithIndex) Forks a value returning task for each item in the specified array.static ForkJoin
static <R> List<R>
join
(Collection<Future<R>> futures) Blocks, if necessary, for the tasks associated with the futures to complete and returns the tasks' results as a List, preserving their order.static <R> R
Blocks, if necessary, for the task associated with the future to complete and returns the task's result.static <R> List<R>
Blocks, if necessary, for the tasks associated with the futures to complete and returns the tasks' results as a List, preserving their order.static <R> List<R>
Blocks, if necessary, for the tasks associated with the futures to complete and returns the tasks' results as a List, preserving their order.static <R> R[]
join
(IntFunction<R[]> returnValueArrayCreator, Future<R>[] futures) Blocks, if necessary, for the tasks associated with the futures to complete and returns the tasks' results as an array, preserving their order.static <R> R[]
join
(IntFunction<R[]> returnValueArrayCreator, Future<R> a, Future<R> b, Future<R>... cToZ) Blocks, if necessary, for the tasks associated with the futures to complete and returns the tasks' results as an array, preserving their order, starting with the result from a, then from b, then from cToZ in order.static <R> List<R>
join_fork_loop
(int min, int maxExclusive, TaskIntFunction<R> intFunction) Blocks, if necessary, for the tasks associated with the fork_loop to complete.static <T,
R> List<R> join_fork_loop
(Iterable<T> iterable, TaskFunction<T, R> function) Blocks, if necessary, for the tasks associated with the fork_loop to complete.static <R> R[]
join_fork_loop
(IntFunction<R[]> returnValueArrayCreator, int min, int maxExclusive, TaskIntFunction<R> intFunction) Blocks, if necessary, for the tasks associated with the fork_loop to complete.static <T,
R> R[] join_fork_loop
(IntFunction<R[]> returnValueArrayCreator, T[] array, TaskFunction<T, R> function) Blocks, if necessary, for the tasks associated with the fork_loop to complete.static <T,
R> List<R> join_fork_loop
(T[] array, TaskFunction<T, R> function) Blocks, if necessary, for the tasks associated with the fork_loop to complete.static <T,
R> List<R> join_fork_loop_with_index
(Iterable<T> iterable, TaskFunctionWithIndex<T, R> functionWithIndex) Blocks, if necessary, for the tasks associated with the fork_loop to complete.static <T,
R> R[] join_fork_loop_with_index
(IntFunction<R[]> returnValueArrayCreator, T[] array, TaskFunctionWithIndex<T, R> functionWithIndex) Blocks, if necessary, for the tasks associated with the fork_loop to complete.static <T,
R> List<R> join_fork_loop_with_index
(T[] array, TaskFunctionWithIndex<T, R> functionWithIndex) Blocks, if necessary, for the tasks associated with the fork_loop to complete.static void
join_void_fork_loop
(int min, int maxExclusive, TaskIntConsumer consumer) Blocks, if necessary, for the tasks associated with the fork_loop to complete.static <T> void
join_void_fork_loop
(Iterable<T> iterable, TaskConsumer<T> consumer) Blocks, if necessary, for the tasks associated with the fork_loop to complete.static <T> void
join_void_fork_loop
(T[] array, TaskConsumer<T> consumer) Blocks, if necessary, for the tasks associated with the fork_loop to complete.static void
join_void_fork_loop_2d
(int aMin, int aMaxExclusive, int bMin, int bMaxExclusive, TaskBiIntConsumer biConsumer) static void
join_void_fork_loop_2d_auto_coarsen
(int aMin, int aMaxExclusive, int bMin, int bMaxExclusive, TaskBiIntConsumer biConsumer) static void
join_void_fork_loop_auto_coarsen
(int min, int maxExclusive, TaskIntConsumer consumer) static <T> void
join_void_fork_loop_with_index
(Iterable<T> iterable, TaskConsumerWithIndex<T> consumerWithIndex) Blocks, if necessary, for the tasks associated with the fork_loop to complete.static <T> void
join_void_fork_loop_with_index
(T[] array, TaskConsumerWithIndex<T> consumerWithIndex) Blocks, if necessary, for the tasks associated with the fork_loop to complete.static ForkJoin
setForkJoin
(ForkJoin forkJoin) void_fork
(TaskRunnable task) Indicates that work defined by a void returning task can be left behind for another idle thread to possibly steal and execute.void_fork_loop
(int min, int maxExclusive, TaskIntConsumer intConsumer) Forks a void returning task for each index in the range [min, maxExclusive).void_fork_loop
(Iterable<T> iterable, TaskConsumer<T> consumer) Forks a void returning task for each element in the specified Iterable.void_fork_loop
(T[] array, TaskConsumer<T> consumer) Forks a void returning task for each item in the specified array.void_fork_loop_with_index
(Iterable<T> iterable, TaskConsumerWithIndex<T> consumerWithIndex) void_fork_loop_with_index
(T[] array, TaskConsumerWithIndex<T> consumerWithIndex) Forks a void returning task for each item in the specified array.
-
Constructor Details
-
FJ
public FJ()
-
-
Method Details
-
fork
Indicates that work defined by a value returning task can be left behind for another idle thread to possibly steal and execute. This method does not block. One can think of this method as creating a fork in the road for the work of the specified task, and then continuing forward along the current path. Another thread is free to pick up this "left behind" work and proceed down its "forked" path. This method returns a Future which can be later joined to: 1) wait for the task to complete, if it has not already, and 2) acquire the supplied result. Note: only invoke this method when the work of the specified task can run before, during, or after all statements which follow it, up to the joining of its returned Future.- Type Parameters:
T
- return type of the task- Parameters:
task
- a value supplying task of work- Returns:
- a Future which can be joined to force the task's completion and acquire its supplied value
-
void_fork
Indicates that work defined by a void returning task can be left behind for another idle thread to possibly steal and execute. This method does not block. Leaves the work of the specified task behind, asfork(fj.api.TaskSupplier<T>)
does, but for a task which does not return a value.- Parameters:
task
- a task of work which does not return a value- Returns:
- a Future which can be joined to force the task's completion
- See Also:
-
join
Blocks, if necessary, for the task associated with the future to complete and returns the task's result.- Type Parameters:
R
- the return type of the future- Parameters:
future
- the future of an associated forked task- Returns:
- the value returned by the task
- Throws:
InterruptedException
- if the current thread was interrupted while waitingExecutionException
- if the task associated with the future threw an exception
-
join
Blocks, if necessary, for the tasks associated with the futures to complete and returns the tasks' results as a List, preserving their order.- Type Parameters:
R
- return type of each task and, it follows, the type of each element in the returned List- Parameters:
futures
- futures associated with forked tasks- Returns:
- Throws:
InterruptedException
- if the current thread was interrupted while waitingExecutionException
- if the task associated with the future threw an exception
-
join
public static <R> R[] join(IntFunction<R[]> returnValueArrayCreator, Future<R>[] futures) throws InterruptedException, ExecutionException Blocks, if necessary, for the tasks associated with the futures to complete and returns the tasks' results as an array, preserving their order.- Type Parameters:
R
- return type of each task and, it follows, the type of each item in the returned array- Parameters:
returnValueArrayCreator
- creator of the array of Future task results to be returnedfutures
- futures associated with forked tasks- Returns:
- Throws:
InterruptedException
- if the current thread was interrupted while waitingExecutionException
- if the task associated with the future threw an exception
-
join
@SafeVarargs public static <R> List<R> join(Future<R> a, Future<R> b, Future<R>... cToZ) throws InterruptedException, ExecutionException Blocks, if necessary, for the tasks associated with the futures to complete and returns the tasks' results as a List, preserving their order.- Type Parameters:
R
- return type of each task and, it follows, the type of each element in the returned List- Parameters:
a
-b
-cToZ
-- Returns:
- Throws:
InterruptedException
- if the current thread was interrupted while waitingExecutionException
- if the task associated with the future threw an exception
-
join
@SafeVarargs public static <R> R[] join(IntFunction<R[]> returnValueArrayCreator, Future<R> a, Future<R> b, Future<R>... cToZ) throws InterruptedException, ExecutionException Blocks, if necessary, for the tasks associated with the futures to complete and returns the tasks' results as an array, preserving their order, starting with the result from a, then from b, then from cToZ in order.- Type Parameters:
R
- return type of each task and, it follows, the type of each item in the returned array- Parameters:
returnValueArrayCreator
- creator of the array of Future task results to be returneda
-b
-cToZ
-- Returns:
- Throws:
InterruptedException
- if the current thread was interrupted while waitingExecutionException
- if the task associated with the future threw an exception
-
join
public static <R> List<R> join(Collection<Future<R>> futures) throws InterruptedException, ExecutionException Blocks, if necessary, for the tasks associated with the futures to complete and returns the tasks' results as a List, preserving their order.- Type Parameters:
R
- return type of each task and, it follows, the type of each element in the returned List- Parameters:
futures
- futures associated with forked tasks- Returns:
- Throws:
InterruptedException
- if the current thread was interrupted while waitingExecutionException
- if the task associated with the future threw an exception
-
fork_loop
Forks a value returning task for each index in the range [min, maxExclusive). The index will be passed to the task function. This method does not block. The returned array of futures will be in the natural order. For example: The future for the min index task will be located in 0th index of the returned array. The future for the maxExclusive-1 index task will be located in the index of the returned array.- Type Parameters:
R
- the return type of the intFunction, and, it follows, the generic type of each Future.- Parameters:
min
- the inclusive minimum of the range to create tasksmaxExclusive
- the exclusive maximum of the range to create tasksintFunction
- function which represents the work for each task, parameterized by its index- Returns:
- an array of Futures associated with each forked task, in natural order
- See Also:
-
void_fork_loop
Forks a void returning task for each index in the range [min, maxExclusive). The index will be passed to the task function. This method does not block.- Parameters:
min
-maxExclusive
-intConsumer
-- Returns:
- See Also:
-
fork_loop
Forks a value returning task for each item in the specified array. The item will be passed to the task function. This method does not block.- Type Parameters:
T
- the type of the input array, and, it follows, the type of the parameter accepted by the task functionR
- the return type of the function, and, it follows, the generic type of each Future.- Parameters:
array
- the input arrayfunction
- the value returning task- Returns:
- an array of Futures associated with each forked task, preserving the order of the input array
- See Also:
-
void_fork_loop
Forks a void returning task for each item in the specified array. The item will be passed to the task function. This method does not block.- Type Parameters:
T
- the type of the input array, and, it follows, the type of the parameter accepted by the task function- Parameters:
array
- the input arrayconsumer
- the void returning task- Returns:
- an array of Futures associated with each forked task, preserving the order of the input array
- See Also:
-
fork_loop
Forks a value returning task for each element in the specified Iterable. The element will be passed to the task function. This method does not block.- Type Parameters:
T
- the type of the input iterable, and, it follows, the type of the parameter accepted by the task functionR
- the return type of the function, and, it follows, the generic type of each Future.- Parameters:
iterable
- the input iterablefunction
- the value returning task- Returns:
- a List of Futures associated with each forked task, preserving the order of the input iterable
- See Also:
-
void_fork_loop
Forks a void returning task for each element in the specified Iterable. The element will be passed to the task function. This method does not block.- Type Parameters:
T
- the type of the input iterable, and, it follows, the type of the parameter accepted by the task function- Parameters:
iterable
- the input iterableconsumer
- the void returning task- Returns:
- a List of Futures associated with each forked task, preserving the order of the input iterable
- See Also:
-
fork_loop_with_index
public static <T,R> Future<R>[] fork_loop_with_index(T[] array, TaskFunctionWithIndex<T, R> functionWithIndex) Forks a value returning task for each item in the specified array. The item along with its index in the array will be passed to the task function. This method does not block.- Type Parameters:
T
- the type of the input array, and, it follows, the type of the first parameter accepted by the task functionR
- the return type of the function, and, it follows, the generic type of each Future.- Parameters:
array
- the input arrayfunctionWithIndex
- the value returning task- Returns:
- an array of Futures associated with each forked task, preserving the order of the input array
-
void_fork_loop_with_index
public static <T> Future<Void>[] void_fork_loop_with_index(T[] array, TaskConsumerWithIndex<T> consumerWithIndex) Forks a void returning task for each item in the specified array. The item along with its index in the array will be passed to the task function. This method does not block.- Type Parameters:
T
- the type of the input array, and, it follows, the type of the first parameter accepted by the task function- Parameters:
array
- the input arrayconsumerWithIndex
- the void returning task- Returns:
- an array of Futures associated with each forked task, preserving the order of the input array
- See Also:
-
fork_loop_with_index
public static <T,R> List<Future<R>> fork_loop_with_index(Iterable<T> iterable, TaskFunctionWithIndex<T, R> functionWithIndex) Forks a value returning task for each item in the specified iterable. The element along with its index in the iterable will be passed to the task function. This method does not block.- Type Parameters:
T
- the type of the input iterable, and, it follows, the type of the first parameter accepted by the task functionR
- the return type of the function, and, it follows, the generic type of each Future.- Parameters:
iterable
- the input iterablefunctionWithIndex
- the value returning task- Returns:
- a List of Futures associated with each forked task, preserving the order of the input iterable
- See Also:
-
void_fork_loop_with_index
public static <T> List<Future<Void>> void_fork_loop_with_index(Iterable<T> iterable, TaskConsumerWithIndex<T> consumerWithIndex) - Type Parameters:
T
- the type of the input iterable, and, it follows, the type of the parameter accepted by the task function- Parameters:
iterable
- the input iterableconsumerWithIndex
- the void returning task- Returns:
- a List of Futures associated with each forked task, preserving the order of the input iterable
- See Also:
-
join_fork_loop
public static <R> R[] join_fork_loop(IntFunction<R[]> returnValueArrayCreator, int min, int maxExclusive, TaskIntFunction<R> intFunction) throws InterruptedException, ExecutionException Blocks, if necessary, for the tasks associated with the fork_loop to complete.- Type Parameters:
R
-- Parameters:
returnValueArrayCreator
-min
-maxExclusive
-intFunction
-- Returns:
- Throws:
InterruptedException
- if the current thread was interrupted while waitingExecutionException
- if the task associated with the future threw an exception- See Also:
-
-
invalid @see
#join(Class, Future[])
fork_loop(int, int, TaskIntFunction)
-
-
join_fork_loop
public static <R> List<R> join_fork_loop(int min, int maxExclusive, TaskIntFunction<R> intFunction) throws InterruptedException, ExecutionException Blocks, if necessary, for the tasks associated with the fork_loop to complete.- Type Parameters:
R
-- Parameters:
min
-maxExclusive
-intFunction
-- Returns:
- Throws:
InterruptedException
- if the current thread was interrupted while waitingExecutionException
- if the task associated with the future threw an exception- See Also:
-
join_fork_loop
public static <T,R> R[] join_fork_loop(IntFunction<R[]> returnValueArrayCreator, T[] array, TaskFunction<T, R> function) throws InterruptedException, ExecutionExceptionBlocks, if necessary, for the tasks associated with the fork_loop to complete.- Type Parameters:
T
-R
-- Parameters:
returnValueArrayCreator
-array
-function
-- Returns:
- Throws:
InterruptedException
- if the current thread was interrupted while waitingExecutionException
- if the task associated with the future threw an exception- See Also:
-
-
invalid @see
#join(Class, Future[])
fork_loop(Object[], TaskFunction)
-
-
join_fork_loop
public static <T,R> List<R> join_fork_loop(T[] array, TaskFunction<T, R> function) throws InterruptedException, ExecutionExceptionBlocks, if necessary, for the tasks associated with the fork_loop to complete.- Type Parameters:
T
-R
-- Parameters:
array
-function
-- Returns:
- Throws:
InterruptedException
- if the current thread was interrupted while waitingExecutionException
- if the task associated with the future threw an exception- See Also:
-
join_fork_loop
public static <T,R> List<R> join_fork_loop(Iterable<T> iterable, TaskFunction<T, R> function) throws InterruptedException, ExecutionExceptionBlocks, if necessary, for the tasks associated with the fork_loop to complete.- Type Parameters:
T
-R
-- Parameters:
iterable
-function
-- Returns:
- Throws:
InterruptedException
- if the current thread was interrupted while waitingExecutionException
- if the task associated with the future threw an exception- See Also:
-
join_fork_loop_with_index
public static <T,R> List<R> join_fork_loop_with_index(Iterable<T> iterable, TaskFunctionWithIndex<T, R> functionWithIndex) throws InterruptedException, ExecutionExceptionBlocks, if necessary, for the tasks associated with the fork_loop to complete.- Type Parameters:
T
-R
-- Parameters:
iterable
-functionWithIndex
-- Returns:
- Throws:
InterruptedException
- if the current thread was interrupted while waitingExecutionException
- if the task associated with the future threw an exception- See Also:
-
join_fork_loop_with_index
public static <T,R> List<R> join_fork_loop_with_index(T[] array, TaskFunctionWithIndex<T, R> functionWithIndex) throws InterruptedException, ExecutionExceptionBlocks, if necessary, for the tasks associated with the fork_loop to complete.- Type Parameters:
T
-R
-- Parameters:
array
-functionWithIndex
-- Returns:
- Throws:
InterruptedException
- if the current thread was interrupted while waitingExecutionException
- if the task associated with the future threw an exception- See Also:
-
join_fork_loop_with_index
public static <T,R> R[] join_fork_loop_with_index(IntFunction<R[]> returnValueArrayCreator, T[] array, TaskFunctionWithIndex<T, R> functionWithIndex) throws InterruptedException, ExecutionExceptionBlocks, if necessary, for the tasks associated with the fork_loop to complete.- Type Parameters:
T
-R
-- Parameters:
returnValueArrayCreator
-array
-functionWithIndex
-- Returns:
- Throws:
InterruptedException
- if the current thread was interrupted while waitingExecutionException
- if the task associated with the future threw an exception- See Also:
-
-
invalid @see
#join(Class, Future[])
fork_loop_with_index(Object[], TaskFunctionWithIndex)
-
-
join_void_fork_loop
public static void join_void_fork_loop(int min, int maxExclusive, TaskIntConsumer consumer) throws InterruptedException, ExecutionException Blocks, if necessary, for the tasks associated with the fork_loop to complete.- Parameters:
min
-maxExclusive
-consumer
-- Throws:
InterruptedException
- if the current thread was interrupted while waitingExecutionException
- if the task associated with the future threw an exception- See Also:
-
join_void_fork_loop
public static <T> void join_void_fork_loop(T[] array, TaskConsumer<T> consumer) throws InterruptedException, ExecutionException Blocks, if necessary, for the tasks associated with the fork_loop to complete.- Type Parameters:
T
-- Parameters:
array
-consumer
-- Throws:
InterruptedException
- if the current thread was interrupted while waitingExecutionException
- if the task associated with the future threw an exception- See Also:
-
join_void_fork_loop
public static <T> void join_void_fork_loop(Iterable<T> iterable, TaskConsumer<T> consumer) throws InterruptedException, ExecutionException Blocks, if necessary, for the tasks associated with the fork_loop to complete.- Type Parameters:
T
-- Parameters:
iterable
-consumer
-- Throws:
InterruptedException
- if the current thread was interrupted while waitingExecutionException
- if the task associated with the future threw an exception- See Also:
-
join_void_fork_loop_with_index
public static <T> void join_void_fork_loop_with_index(Iterable<T> iterable, TaskConsumerWithIndex<T> consumerWithIndex) throws InterruptedException, ExecutionException Blocks, if necessary, for the tasks associated with the fork_loop to complete.- Type Parameters:
T
-- Parameters:
iterable
-consumerWithIndex
-- Throws:
InterruptedException
- if the current thread was interrupted while waitingExecutionException
- if the task associated with the future threw an exception- See Also:
-
join_void_fork_loop_with_index
public static <T> void join_void_fork_loop_with_index(T[] array, TaskConsumerWithIndex<T> consumerWithIndex) throws InterruptedException, ExecutionException Blocks, if necessary, for the tasks associated with the fork_loop to complete.- Type Parameters:
T
-- Parameters:
array
-consumerWithIndex
-- Throws:
InterruptedException
- if the current thread was interrupted while waitingExecutionException
- if the task associated with the future threw an exception- See Also:
-
join_void_fork_loop_auto_coarsen
public static void join_void_fork_loop_auto_coarsen(int min, int maxExclusive, TaskIntConsumer consumer) throws InterruptedException, ExecutionException -
join_void_fork_loop_2d
public static void join_void_fork_loop_2d(int aMin, int aMaxExclusive, int bMin, int bMaxExclusive, TaskBiIntConsumer biConsumer) throws InterruptedException, ExecutionException -
join_void_fork_loop_2d_auto_coarsen
public static void join_void_fork_loop_2d_auto_coarsen(int aMin, int aMaxExclusive, int bMin, int bMaxExclusive, TaskBiIntConsumer biConsumer) throws InterruptedException, ExecutionException -
getForkJoin
-
setForkJoin
-