commons-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From a..@apache.org
Subject commons-scxml git commit: SCXML-263 Javascript engine (Nashorn) cannot be shared between multiple SCXML instance executions
Date Sun, 10 Dec 2017 14:33:08 GMT
Repository: commons-scxml
Updated Branches:
  refs/heads/master 8da7f06a6 -> b5dd05b28


SCXML-263 Javascript engine (Nashorn) cannot be shared between multiple SCXML instance executions


Project: http://git-wip-us.apache.org/repos/asf/commons-scxml/repo
Commit: http://git-wip-us.apache.org/repos/asf/commons-scxml/commit/b5dd05b2
Tree: http://git-wip-us.apache.org/repos/asf/commons-scxml/tree/b5dd05b2
Diff: http://git-wip-us.apache.org/repos/asf/commons-scxml/diff/b5dd05b2

Branch: refs/heads/master
Commit: b5dd05b28613314e66cbd20906daf40424433331
Parents: 8da7f06
Author: Ate Douma <ate@apache.org>
Authored: Sun Dec 10 15:33:02 2017 +0100
Committer: Ate Douma <ate@apache.org>
Committed: Sun Dec 10 15:33:02 2017 +0100

----------------------------------------------------------------------
 src/changes/changes.xml                           |  4 ++++
 .../scxml2/env/javascript/JSEvaluator.java        | 18 ++++++++++--------
 2 files changed, 14 insertions(+), 8 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/commons-scxml/blob/b5dd05b2/src/changes/changes.xml
----------------------------------------------------------------------
diff --git a/src/changes/changes.xml b/src/changes/changes.xml
index 369626e..f5c434c 100644
--- a/src/changes/changes.xml
+++ b/src/changes/changes.xml
@@ -35,6 +35,10 @@
     <release version="2.0" date="In Git master"
       description="Latest unreleased code">
 
+      <action dev="ate" type="update" issue="SCXML-263">
+        [12-10-2017] Javascript engine (Nashorn) cannot be shared between multiple SCXML
instance executions
+      </action>
+
       <action dev="ate" type="update" issue="SCXML-262">
         [12-10-2017] Support &lt;script&gt; loaded from external src
       </action>

http://git-wip-us.apache.org/repos/asf/commons-scxml/blob/b5dd05b2/src/main/java/org/apache/commons/scxml2/env/javascript/JSEvaluator.java
----------------------------------------------------------------------
diff --git a/src/main/java/org/apache/commons/scxml2/env/javascript/JSEvaluator.java b/src/main/java/org/apache/commons/scxml2/env/javascript/JSEvaluator.java
index 66f829c..b007b62 100644
--- a/src/main/java/org/apache/commons/scxml2/env/javascript/JSEvaluator.java
+++ b/src/main/java/org/apache/commons/scxml2/env/javascript/JSEvaluator.java
@@ -94,8 +94,8 @@ public class JSEvaluator extends AbstractBaseEvaluator {
     private static final String ERR_CTX_TYPE = "Error evaluating JavaScript "
             + "expression, Context must be a org.apache.commons.scxml2.env.javascript.JSContext";
 
-    /** shared singleton Nashorn ScriptEngine **/
-    private static ScriptEngine engine;
+    /** Nashorn ScriptEngine **/
+    private transient ScriptEngine engine;
 
     /** Nashorn Global initialization script, loaded from <code>init_global.js</code>
classpath resource */
     private static String initGlobalsScript;
@@ -112,14 +112,16 @@ public class JSEvaluator extends AbstractBaseEvaluator {
      * initialization of a new Javascript (Nashorn) Global.
      * </p>
      */
-    protected synchronized static void initEngine() {
+    protected synchronized void initEngine() {
         if (engine == null) {
             engine = new ScriptEngineManager().getEngineByName("JavaScript");
-            try {
-                initGlobalsScript = IOUtils.toString(JSEvaluator.class.getResourceAsStream("init_global.js"),
"UTF-8");
-            }
-            catch (IOException ioe) {
-                throw new RuntimeException("Failed to load init_global.js from classpath",
ioe);
+            if (initGlobalsScript == null) {
+                try {
+                    initGlobalsScript = IOUtils.toString(JSEvaluator.class.getResourceAsStream("init_global.js"),
"UTF-8");
+                }
+                catch (IOException ioe) {
+                    throw new RuntimeException("Failed to load init_global.js from classpath",
ioe);
+                }
             }
         }
     }


Mime
View raw message