Reputation: 3
I am unsure about which to use in performance wise. Which should be used? Both version have the some functionality.
Code snippet 1
fileMap.values().stream().parallel().forEach(file -> {
downlod(file);
});
Code snippet 2
fileMap.values().forEach(file -> {
executor.execute(file);
}
Upvotes: 0
Views: 62
Reputation: 32517
In case of heavy computation task, go with separate executor. parallelStream
uses shared thread pool, thus heavy tasks can potentially block parallelStreams
in other parts of application.
Upvotes: 1