开发者

Java Future and infinite computation

开发者 https://www.devze.com 2022-12-24 13:47 出处:网络
I\'m trying to optimize an (infinite) computation algorithm. I have an infinte Sum to calculate ( Summ_{n-> infinity} (....))

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开发者_如何学Go 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!


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.

0

精彩评论

暂无评论...
验证码 换一张
取 消