Java – are there any tips and tricks to make rhinoceros perform faster?
•
Java
Are there any tips & Tips for rhinoceros to perform faster? I'm trying to use uglifyjs in rhino to compress large JS files, which takes more than a minute Do you have any hints or other choices about rhino in Java server-side space?
Solution
Using the JavaScript API on rhino, you only need to compile the script using the compiled interface For example:
public class CompileScript { public static void main(String[] args) throws ScriptException { ScriptEngineManager engineManager = new ScriptEngineManager(); ScriptEngine scriptEngine = engineManager.getEngineByName("js"); //cast to Compilable engine,this is safe for Rhino Compilable c = (Compilable) scriptEngine; CompiledScript script = c.compile("print('Hello World')"); //compile script.eval(); } }
However, this can be beneficial when the script is run several times Basically, it reduces the cost of each reinterpretation From compiledscript Javadoc:
Anyway, I think you should take a look at rhino JavaScript compiler It "converts javascript source code into Java class files."
There is also a V8 Java implementation Check jav8
The content of this article comes from the network collection of netizens. It is used as a learning reference. The copyright belongs to the original author.
THE END
二维码