我想知道是否有人可以指出我在 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.
更新:如何在 java 中进行多处理,以及预计速度会提高多少?
这似乎表明线程是要走的路.我希望我别无选择,只能涉入一堆船闸(双关语无意)并等待我的船航行.尽管如此,还是欢迎简单的例子.
This seems to indicate threads is the way to go. I expect I have no choice but wade into a bunch of locks (pun unintended) and wait for my ship to sail. Simple examples are welcome nevertheless.
没有完全兼容的类,但是 ExecutorService 为您提供实现它所需的一切.
There's no exactly-compatible class, but ExecutorService gives you everything you need to implement it.
特别是,没有将 Callable 映射到 Collection 并等待结果的函数,但您可以轻松构建 Collection<Callable<T>> 出 Callable<T> 和 CollectioninvokeAll,它会返回一个列表<未来<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 中的一些其他函数,则需要循环 submit 并构建自己的等待集合开.但是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.)
这篇关于Python pool.map/Multiprocessing 的 Java 等效项的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持html5模板网!
解析 ISO 8601 字符串本地日期时间,就像在 UTC 中Parsing an ISO 8601 string local date-time as if in UTC(解析 ISO 8601 字符串本地日期时间,就像在 UTC 中一样)
如何将公历字符串转换为公历?How to convert Gregorian string to Gregorian Calendar?(如何将公历字符串转换为公历?)
Java:GregorianCalendar 的最大值和最小值是什么/在哪Java: What/where are the maximum and minimum values of a GregorianCalendar?(Java:GregorianCalendar 的最大值和最小值是什么/在哪里?)
1582 年 10 月 15 日之前日期的日历到日期转换.公历Calendar to Date conversion for dates before 15 Oct 1582. Gregorian to Julian calendar switch(1582 年 10 月 15 日之前日期的日历到日期转换
java日历setFirstDayOfWeek不起作用java Calendar setFirstDayOfWeek not working(java日历setFirstDayOfWeek不起作用)
Java:获取当前星期几的值Java: getting current Day of the Week value(Java:获取当前星期几的值)