c12
c12

Reputation: 9827

Parallel Processing Java Collection

What is the best approach to parallel process a Collection of Java Objects? I would like to have a threadpool of a 100 threads each work on a separate Collection object and perform some action on it. Any ideas? Java 8 is the targeted version.

Upvotes: 1

Views: 304

Answers (1)

Paul Hicks
Paul Hicks

Reputation: 13999

Use a parallelStream.

yourCollection
  .parallelStream()
  .forEach(e -> doStuff(e));

You may also want to collect() the results afterwards.

Upvotes: 4

Related Questions