This is the problem I have: I have a large sequence of some objects (List<SomeClass>
), and want to perform some operation on all elements of list and get a new sequence (List<SomeOtherClass>
).
Like:
List<SomeOtherClass> list = new ArrayList<SomeOtherClass>();
for(SomeClass sc : originalList)
list.add(someOperation(sc));
Since operation someOperation
does not have any side effects, and the list is quite large, I want this mapping operation to be parallelized.
What will be the best way to do that in Java?
A possible implementation can utilize the Executor framework (example included).
Use threading and partition your work using sublists.
Split the input list, and use FutureTask task, then merge the results
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With