1. Option A. JDK 6 starts with the built-in Rhino engine B. jdk8 replacement Nashorn (high performance, better for ECMA Support) C. Java version of Nodejs Vertx.io 2. Practical operation
public static void Main (string[] args) {Scriptenginemanager manager = new Scriptenginemanager (); ScriptEngine engine = Manager.getenginebyname ("Nashorn"); try {int value=2; Simplebindings bind=new simplebindings (); Simplebindings bind2=new simplebindings (); Simplebindings bind3=new simplebindings (); Bind.put ("Points", value); Bind2.put ("A", value); Bind2.put ("B", value); Bind3.put ("A1", value+1); Bind3.put ("B1", value+2); System.out.println (Engine.eval ("Points <50?50:math.ceil (56/50) *50", bind)); System.out.println (Engine.eval ("Demosum=function (A, b) {return a+b}; Demosum (A, b); ", Bind2)); Defines the method and invokes the support parameter binding System.out.println (Engine.eval (function (A1,B1) {function demosub (A, b) {return a+b;} Return Demosub (A1,B1)}) (A1,B1) ", Bind3)"; Use JS to execute function immediately} catch (Scriptexception e) {e.printstacktrace (); } }
3. Docker container handling Docker container in practice there is a principle that the image of the container should be as small as possible general people will choose to use the Alpine Linux distribution for Dockerfile as follows:
FROM frolvlad/alpine-oraclejdk8:fullVOLUME /tmpADD demo.class demo.classRUN ln -sf /usr/share/zoneinfo/Asia/Shanghai /etc/localtimeENTRYPOINT ["java","-Djava.security.egd=file:/dev/./urandom","app"]
Note the tag selection of the image uses the full execution result
Java execution JavaScript and container-session issues