问题描述
我想知道是否有人可以指点我在java中使用python的多处理模块。
I was wondering if somebody could point me to a simple equivalent of python's multiprocessing module in java.
我有一个简单的并行处理场景(其中没有2个进程交互):获取数据集并将其拆分为12并将java方法应用于12个数据集,收集结果并将它们连接到具有相同排序的某种列表中。
I have a simple parallel processing scenario (where no 2 processes interact): Take a data set and split it into 12 and apply a java method to the 12 datasets, collect results and join them in a list of some sort with the same ordering.
Java是一种专业语言似乎有多个库和方法 - 任何可以帮助这个java新手的人都可以开始使用?
Java being a "pro" language appears to have multiple libraries and methods - anyone who can help this java newbie get started?
我想用最少的编码 - 正如我所说,我的要求非常简单。
I would like to do this with minimal of coding - as i said my requirement is pretty straightforward.
更新:
为您提供一切我需要实现它。
There's no exactly-compatible class, but ExecutorService
gives you everything you need to implement it.
特别是,没有函数可以在 Callable >集合并等待结果,但您可以轻松地从集合< Callable< T>> > Callable< T> 和 Collection< T>
,然后只需调用 invokeAll
,其中返回列表< Future< T>>
。
In particular, there's no function to map a Callable
over a Collection
and wait on the results, but you can easily build a Collection<Callable<T>>
out of a Callable<T>
and Collection<T>
, then just call invokeAll
, which returns you a List<Future<T>>
.
(如果你想模仿其他一些来自 multiprocessing.Pool
的函数,你需要循环提交
,然后构建你自己的东西集合等待但是 map
很简单。)
(If you want to emulate some of the other functions from multiprocessing.Pool
, you will need to loop around submit
instead and build your own collection of things to wait on. But map
is simple.)
这篇关于Java pool.map/ Multiprocessing的Java等价物的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!