Question

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!

Was it helpful?

Solution

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.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top