问题
Why ForkJoinPool was forked for Scala?
Which implementation and for which case is preferred?
回答1:
The obvious reason for the scala library to have its own copy of ForkJoinPool is that scala must run on pre-1.7 JVMs, and ForkJoinPool
was only introduced in Java 1.7.
In addition, there were a few changes made for internal (scala) use, such as this:
https://github.com/scala/scala/commit/76e9da2ca4c31daec2b04848c3c2dbad6ecd426e
Given that scala's version will probably not give you any advantage (if you are compiling and running against java 1.7), I'd say that for you own use you should probably use java's version. At least java's version is precisely documented and fully "public", while the status of scala's version is unclear (it might very well be intended for internal use only). However in some places you might not have any choice. By example ForkJoinTasks
has a forkJoinPool
method that expects scala's version of ForkJoinPool
. If someone can get/find any official status for scala's version of ForkJoinPool
stating that it's really public and stable, then I'll happily revert this advice.
来源:https://stackoverflow.com/questions/14562070/scala-concurrent-forkjoin-forkjoinpool-vs-java-util-concurrent-forkjoinpool