How to use Nashorn in Java 15 and later?

According to JEP 372, Nashorn had been removed from JDK 15 but you can get latest nashorn from https://search.maven.org/artifact/org.openjdk.nashorn/nashorn-core/15.0/jar For Maven, include the below dependency into your pom.xml <dependency> <groupId>org.openjdk.nashorn</groupId> <artifactId>nashorn-core</artifactId> <version>15.0</version> </dependency> For Gradle, include dependency below into your build.gradle implementation ‘org.openjdk.nashorn:nashorn-core:15.0’ Unfortunately, Standalone Nashorn is only usable as a JPMS module. So you … Read more

Should I use a separate ScriptEngine and CompiledScript instances per each thread?

You can share a ScriptEngine and CompiledScript objects across threads. They are threadsafe. Actually, you should share them, as a single engine instance is a holder for a class cache and for JavaScript objects’ hidden classes, so by having only one you cut down on repeated compilation. What you can’t share is Bindings objects. The … Read more