[concurrency-interest] ThreadPoolExecutor - Concurrent "Batch" Executions

Martin Buchholz martinrb at google.com
Thu May 20 01:47:19 EDT 2010

Is this what you're looking for?

long, java.util.concurrent.TimeUnit)


On Wed, May 19, 2010 at 20:13, Mike Boyers <mboyers at yahoo.com> wrote:
> I'm building a service where, in order to generate each response, I'll need to go against several remote sources.  In many cases, the remote requests can be made concurrently.
> I'm looking for a super simple interface where developers can execute these remote requests in parallel while being blocked as they execute, with the ability to time out after a specified period.
> As a (very) rough idea:
> Collection batch = new LinkedList();
> batch.add(new RemoteRequest1());
> batch.add(new RemoteRequest2());
> batch.add(new RemoteRequest3());
> Batcher.execute(batch, 5, TimeUnit.SECONDS);
> The Batcher.execute call blocks until either all of the tasks are complete or until 10 seconds passes.
> I can see how to use a ThreadPoolExecutor to accomplish this, by submitting each Callable then waiting on the Future objects returned upon submit, meanwhile keeping track of the overall amount of time I've waited as I wait on each Future.  While this logic isn't overly complicated, I'd still like to keep it housed and supply developers with something like I outlined above.
> But before building this "wrapper", I figure I'd ask to see if there's already something existing I should be looking at, either in the concurrent package or elsewhere (or if I should be thinking about this in a completely different way).
> Thanks,
> Mike
> _______________________________________________
> Concurrency-interest mailing list
> Concurrency-interest at cs.oswego.edu
> http://cs.oswego.edu/mailman/listinfo/concurrency-interest

More information about the Concurrency-interest mailing list