[concurrency-interest] Making ExecutorService return on first failure?

jason marshall jdmarshall at gmail.com
Thu Mar 12 15:17:43 EDT 2009


I'm trying to use ExecutorService to set up initial conditions for a cluster
of work.

if (Parallel setup)
  Sequential tasks
finally
  Parallel teardown


What I'm seeing is fairly degenerate behavior in a couple of cases that I'd
like to avoid, but I haven't thought of a way to do it within the current
bounds of the j.u.c framework.

The most apparent issue I have is that there is no early abort mechanism.
You can either poll all queued tasks manually, or you can wait for all to
succeed or fail.

If I have 3 worker threads (empirically this completes the fastest on our
4-processor box), and task #2 errors out, it does me no good to dequeue task
#5 and start working on it; the entire exercise is a bust anyway.  What I
want to do is clean up and declare failure ASAP.


Short of going to a fully poll-based arrangement, I don't see a way to get
this behavior.  Well, okay, I see one way to do it, and that's to have the
failing Callable suicide (terminate the Executor).  But I'm not sure that
ExecutorService supports mutual recursion with its own tasks.  In fact now
that I think about it, I would be quite surprised if they do.

Anyone have any ideas or experience to share?

Thanks,
Jason






-- 
- Jason
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://cs.oswego.edu/pipermail/concurrency-interest/attachments/20090312/5e00a9dd/attachment.html>


More information about the Concurrency-interest mailing list