jparfor
Class MultiThreader

java.lang.Object
  extended by jparfor.MultiThreader

public final class MultiThreader
extends java.lang.Object

MultiThreader providing foreach functions enabling parallel computations of the content of for loops.


Method Summary
static
<I,R> java.util.ArrayList<R>
foreach(java.lang.Iterable<I> inputs, Functor<I,R> functor)
          Execute the functor on all inputs.
static
<I,R> java.util.ArrayList<R>
foreach(java.lang.Iterable<I> inputs, int concurrentSize, Functor<I,R> functor)
          Execute the functor on all inputs.
static int getNumberOfAvailableProcessors()
          Return the number of processors used by the multithreader.
 
Methods inherited from class java.lang.Object
equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Method Detail

foreach

public static <I,R> java.util.ArrayList<R> foreach(java.lang.Iterable<I> inputs,
                                                   Functor<I,R> functor)
Execute the functor on all inputs. All the inputs from the inputs iterable object are created and placed in a collection for multithread processing. The results are returned in the same order that the inputs iterable created them.

Type Parameters:
I - Type of input to the functor.
R - Type of results from the functor.
Parameters:
inputs - Collection of inputs to send to the functor.
functor - Functor that will compute results from inputs.
Returns:
a Collection containing all the results calculated on the inputs with the functor.

foreach

public static <I,R> java.util.ArrayList<R> foreach(java.lang.Iterable<I> inputs,
                                                   int concurrentSize,
                                                   Functor<I,R> functor)
Execute the functor on all inputs. Only concurrent inputs from the inputs iterable object are created and placed in a collection for multithread processing at one time. Multiple batch are created until all inputs from the iterable object have been computed. The results are returned in the same order that the inputs iterable created them. This function can be used if the inputs size for the functor is memory intensive and one cannot afford to create them all at the same time. Note that the results must still be able to hold in memory all at the same time.

Type Parameters:
I - Type of input to the functor.
R - Type of results from the functor.
Parameters:
inputs - Collection of inputs to send to the functor.
concurrentSize - Maximum number of inputs to process in a batch (if set to -1, all inputs will be computed at once). The inputs are put in batches according to the order given by the iterator.
functor - Functor that will compute results from inputs.
Returns:
a Collection containing all the results calculated on the inputs with the functor.

getNumberOfAvailableProcessors

public static int getNumberOfAvailableProcessors()
Return the number of processors used by the multithreader.

Returns:
the number of processors used by the multithreader.