简体   繁体   中英

Thread in stream vs Parallel Stream

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);
}

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.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM