简体   繁体   中英

Parallelism issues when calling java from groovy

I've got a large Java framework which uses a lot of parallel execution (Thread pools, Java 8 streams, etc). It works fin when I am using it in pure Java and loads all my 8 cores to the maximum on computation heavy tasks.

Now I made a thin Groovy wrapper for my java classes to simplify configuration. What I expect is that I will have a slight performance overhead on Groovy calls but the compiled Java classes should perform just the same. In practice, I see that there is a huge drop of performance and the program utilizes only one or two cores to 40-50%. When I wrap the Groovy code in GroovyShell and call it from the Java main class, all works fine and I have my 100% performance back.

What is the problem? Does Groovy launcher override some default thread pooling configuration?

I am using Java 8, Groovy 2.4.7 and calling Groovy scripts from Idea.

I found the problem. It is not with java thread pool, it is with Groovyshell . I have a GroovyShell calls inside my java code so when I call it from java it works fine, but when I call it from groovy, it for some reason causes current thread to wait for GroovyShell call to finish on another thread (even if I have different shell objects).

I've included synchronized parsed script caching (script is parsed once and then used with different bindings) and it solved the problem (also greatly improved performance of this part of code).

The only problem is that since there is no obvious way to clone script and distribute it for different threads, I need to synchronize calls.

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