The reason people say functional languages are better for parallel processing is due to the fact that they usually avoid mutable state. Mutable state is the "root of all evil" in the context of parallel processing, because itsprocessing; they make it really easy to run into race conditions, when they are shared between concurrent processes. The solution to which the solutions tend torace conditions then involve a lot of locking and synching mechanisms, as you mentioned, which cause runtime overhead and a lot, as the processes wait for one another to make use of extrathe shared resource, and greater design complexity, as all of these concepts tend to be deeply nested within such applications.
AvoidingWhen you avoid mutable state, the need for synchronization and locking mechanisms, or in short, disappears along with it. Because functional languages usually avoid mutable state, is what makes a programthey are naturally more efficient and effective for parallel processing - you won't have the runtime overhead of shared resources, and you won't have the added design complexity that usually follows. In other words
However, ifthis is all incidental. If your solution in Java does not usealso avoids mutable state (at least not within objectsspecifically shared between threads), converting it to a functional language like Scala or Clojure would not yield any benefits in termterms of the multithreading capacity (although there are certainly other factors involved, which are not in the scope of this discussion)concurrent efficiency, because the original solution is already free of the overhead caused by the locking and synching mechanisms.
So to aswer your question more directlyTL;DR: If a solution in Scala is more efficient in parallel processing than one in Java, it is not because of the way the code is compiled or run through the JVM, but instead because the Java solution is usingsharing mutable state between threads, either causing race conditions or adding the overhead of synchronization in order to avoid them.