Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Why is Scala building its own ForkJoinPool instead of using java.util.concurrent.ForkJoinPool#commonPool? [duplicate]

Both Java and Scala introduce their own global ForkJoinPool, Java as java.util.concurrent.ForkJoinPool#commonPool and Scala as scala.concurrent.ExecutionContext#global. Both of these seem to be intended to be used for the same use cases, specifically running non-blocking concurrent tasks (often implicitly). Now from what I can figure, if you pick your interop dependencies the wrong way, you will end up with two thread pools doing exactly the same thing, one for the Java world and one for the Scala world.

So unless I am missing something obvious, is there any good reason for Scala to not simply use the Java commonPool for its global ExecutionContext?

like image 788
ludicarno Avatar asked May 15 '19 09:05

ludicarno


People also ask

How do I replace forkjoinpool with unsafe in Java?

* Replace with a simple call to Unsafe.getUnsafe when integrating * into a jdk. * * @return a sun.misc.Unsafe */ private static sun.misc.Unsafe getUnsafe () { return scala.concurrent.util.Unsafe.instance; } } Here is a short list of links related to this Scala ForkJoinPool.java source code file:

What is the forkjoinpool class?

The ForkJoinPool class is the center of the fork/join framework, which is an implementation of the ExecutorService interface.

What are some good examples of Scala programming languages?

(For my Scala work, see my Scala examples and tutorials .) abase, ac_shift, ashift, concurrent, countedcompleter, ctl, forkjoin, forkjoinpool, forkjointask, pl_lock, smask, workqueue

Can I use commonpool to block tasks?

However, if you intend to use commonPool for blocking tasks, then you need to consider some consequences.


1 Answers

To add to other answers - besides JVM version issue, usage of JVM specific implementation would bound Scala API to Java internals. Even if that wasn't the goal initially, right now Scala community would like to target more than one backend: we have Scala, Scala.js, Scala Native. If we decide to change things and couple Scala library to JVM API code will be less portable for no good reason - after all ExecutionContext on JVM still uses some Java's thread pool implementations internally, so it's not like we are reinventing the wheel.

like image 177
Mateusz Kubuszok Avatar answered Oct 16 '22 21:10

Mateusz Kubuszok