Java equivalent for Python pool.map/ Multiprocessing

后端 未结 1 468
离开以前
离开以前 2021-01-03 01:38

I was wondering if somebody could point me to a simple equivalent of python\'s multiprocessing module in java.

I have a simple parallel processing scenario (where no

1条回答
  •  半阙折子戏
    2021-01-03 02:21

    There's no exactly-compatible class, but ExecutorService gives you everything you need to implement it.

    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> out of a Callable and Collection, then just call invokeAll, which returns you a List>.

    (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.)

    0 讨论(0)
提交回复
热议问题