[concurrency-interest] jsr166y.forkjoin API comments

Doug Lea dl at cs.oswego.edu
Tue Jan 29 07:21:52 EST 2008


David J. Biesack wrote:

> sometimes you want fork/join but you don't have an array to operate on; you
> just have a set of indices. 

This suggests creating something like the following.

class ParallelIntLoop {
     // Constructors, or maybe factories
     ParallelIntLoop(int firstIndex, int upperBound);
     ParallelIntLoop(int firstIndex, int upperBound, int increment);
     ParallelIntLoop(int firstIndex, int upperBound,
                     ForkJoinExecutor ex);
     ParallelIntLoop(int firstIndex, int upperBound, int increment,
                     ForkJoinExecutor ex);
     // Apply to each index
     void apply(IntProcedure p);
     // Map each index and reduce
     <T> T reduce(IntToObject<T> op, Reducer<T> r, T base);
     // Plus scalar specializations, like:
     long reduce(IntToLong op, LongReducer r, long base);
     // Plus basic layered forms, including
     <T> T max(IntToObject<T> op);
}

Plus a version using longs rather than ints.

What do you think?

-Doug



More information about the Concurrency-interest mailing list