Arrays.sort() 和 Arrays.parallelSort() 的区别 [英] Difference between Arrays.sort() and Arrays.parallelSort()

查看:36
本文介绍了Arrays.sort() 和 Arrays.parallelSort() 的区别的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

正在研究 Java 8 特性,提到

Was going through Java 8 features, mentioned here. Couldn't understand what parallelSort() does exactly. Can someone explain what is the actual difference between sort() and parallelSort()?

解决方案

Parallel sort uses threading - each thread gets a chunk of the list and all the chunks are sorted it in parallel. These sorted chunks are then merged into a result.

It's faster when there are a lot of elements in the collection. The overhead for parallelization (splitting into chunks and merging) becomes tolerably small on larger collections, but it is large for smaller ones.

Take a look at this table (of course, the results depend on the CPU, number of cores, background processes, etc):

Taken from this link: http://www.javacodegeeks.com/2013/04/arrays-sort-versus-arrays-parallelsort.html

这篇关于Arrays.sort() 和 Arrays.parallelSort() 的区别的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆