java-json-tools / json-schema-core

Core support architecture for json-schema-validator and other processors
Other
67 stars 57 forks source link

Add support for GraalJS script engine as possible replacement for the deprecated Nashorn #96

Open sdoeringNew opened 3 years ago

sdoeringNew commented 3 years ago

With Java 15 Nashorn was finally removed from the JDK. But with GraalJS there is some sort of replacement.

If the application runs with the polyglot GraalVM there is out of the box support for GraalJS. Or GraalJS and its ScriptEngine could be simply added as dependency and ran with the JDK.

sdoeringNew commented 3 years ago

But there is one caveat.

JavaScript is single threaded. Rhino and Nashorn haven't cared but GraalJS does. Multi-threaded access to the same context will result in an exception.

See: https://www.graalvm.org/reference-manual/js/Multithreading/

One of the recommendations is proper synchronization. And I think I'll go with that. A synchronized access to the GraalJS script engine shall still be faster than multi-threaded Rhino. GraalJS is magnitudes faster than Rhino.