[concurrency-interest] jsr166y.forkjoin API comments

David J. Biesack David.Biesack at sas.com
Mon Jan 28 15:35:33 EST 2008

I wrote:

> Having written this example, I come away with two (new!) API comments
> which I'll post separately.

Here is the second observation. A bit long, sorry.

In http://artisans-serverintellect-com.si-eioswww6.com/default.asp?W40 I wanted to operate on the indices only, but not replace the values. Thus, I wanted apply() instead of replaceWithMapping(). But Ops.Procedure was insufficient because it does not pass the index. That is, I wanted a operation interface that has the signature

   void op(int index, A value>);

I ended up using Ops.IntToObject<A> and simply ignoring the result.

Rather than introduce a new interface and new apply() method, I think the ForkJoin API can be lightened by removing the various *Procedure types and replacing them with the existing IntAnd{Type}To{Type} (i.e. IntAndDoubleToDouble, IntAndObjectToObject, etc.) operators and changing apply() to take that same operator type; apply() simply ignores the Op's output (which can be Void typed).

   Ops.DoubleProcedure                use Ops.IntAndDoubleToDouble
   Ops.IntAndDoubleProcedure          use Ops.IntAndDoubleToDouble
   Ops.IntAndObjectProcedure<A>       use Ops.IntAndObjectToObject
   Ops.LongProcedure                  use Ops.IntAndLongToLong
   Ops.Procedure<A>                   use Ops.IntAndObjectToObject

But wait, there's more. The API could be further simplified if some of the methods which do not use the index or the value are consolidated with the indexed variants. For example, in ParallelArray there are three similar methods (generic stripped for simplicity)

 ParallelArray replaceWithMappedIndex(Ops.IntToObject op)
 ParallelArray replaceWithMapping(Ops.Op op)
 ParallelArray replaceWithMappedIndex(Ops.IntAndObjectToObject op)

which can be replaced with a single method:

   ParallelArray mapped(Ops.IntAndObjectToObject op)

as follows:

ParallelArray replaceWithMappedIndex(Ops.IntToObject<Void> op)

    ignore the Void b parameter

ParallelArray replaceWithMapping(Ops.Op op)

    ignore the int a parameter.

ParallelArray replaceWithMappedIndex(Ops.IntAndObjectToObject op)

   this method is renamed to mapped.

Just a thought.

(Sidebar: I don't see uses of many of the Procedure types actually used anywhere in jsr166y.forkjoin. Defined but not used anywhere are:


Perhaps these unused interfaces are designated for an upcoming forkjoin ParallelMap.)

David J. Biesack     SAS Institute Inc.
(919) 531-7771       SAS Campus Drive
http://www.sas.com   Cary, NC 27513

More information about the Concurrency-interest mailing list