tags:

views:

63

answers:

1

I'm trying to optimize an (infinite) computation algorithm.

I have an infinte Sum to calculate ( Summ_{n-> infinity} (....) ) My idea was to create several threads using the Future < > construct, then combine the intermediate results together. My problem hoewer is that I need a certain precision. So I need to constantly calculate the current result while other threads keep calculating.

My question is: Is there some sort of result queue where each finished thread can put its results in, while a main thread can receive those results and then either lets the computation continues or terminate the whole ExecutorService?

Any Help would really be appreciated! Thanks!

+2  A: 

A blocking queue maybe ( http://java.sun.com/j2se/1.5.0/docs/api/java/util/concurrent/BlockingQueue.html )? The main thread can block on that until a partial result arrives and then update the total.

David Soroko
thanks! that does the trick for me.
Chris