[concurrency-interest] Re: new task coordination operations (Doug Lea)

David J. Biesack David.Biesack@sas.com
Tue, 16 Dec 2003 10:15:50 -0500 (EST)


 
> The second is to new methods invokeAny and invokeAll in
> ExecutorService. These take lists of tasks, execute them all, and then
> wait for at least one (invokeAny) or all (invokeAll) to complete.
> While these can be implemented easily using a CompletionService, they
> are common enough to expose separately, and also admit special-purpose
> solutions that might be a bit more efficient in some ExecutorServices
> than you could obtain yourself.

Whenever I see two (and only two) options in an API, I think "looks like
an opportunity for a strategy pattern". 

I know it's tempting/dangerous to overengineer, but is there some use in
a generic invoke() method which takes a completion strategy object as a
parameter? The two degenerate cases above (one completes, all completes)
can be implemented with specific completion strategy objects available
from a factory method.

Sorry, I don't have a specific use case from an actual system, but I can
imagine several: n worker classes and 1 'escape' task - complete when
the n workers finish, or when the escape task finishes. Or, perhaps
I complete when I've found a 'majority' answer to a predicate function.

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