Java parallel work iterator?

前端 未结 3 1402
后悔当初
后悔当初 2021-01-19 02:05

I\'m looking for a class where I can override a method to do the work, and return the results like an iterator. Something like this:

ParallelWorkIterator<         


        
3条回答
  •  天命终不由人
    2021-01-19 02:46

    I would recommend looking at Java Executors.

    You submit a number of tasks and get a Future object back for each one. Your work is processed in the background, and you iterate through the Future objects (like you do in the above). Each Future returns a result as it become available (by calling get() - this blocks until the result has been generated in a separate thread)

提交回复
热议问题