AnsweredAssumed Answered

Script evaluation in a separated thread

Question asked by mathiasd on Sep 23, 2011
Latest reply on Sep 23, 2011 by mathiasd
Is it possible to run script evaluations in a separated thread ? I made my own script engine which uses the javascript engine.
I have something like that :

public Object eval(String script, Bindings n) throws ScriptException {
        ScriptThread thread = new ScriptThread(javascriptEngine,script,n);
        long startTime = System.currentTimeMillis();
        while(System.currentTimeMillis()-startTime < 10000 && thread.getResult() == null);
        Object result = thread.getResult();
        if(result == null) {
            throw new ScriptException("Script execution was too long");
        return result;

And the scriptThread is simply :

    public void run() {
        try {
            result = engine.eval(script, bindings);
        } catch (ScriptException e) {

But when I run this code I have :

Exception in thread "Thread-2" java.lang.NullPointerException
   at org.activiti.engine.impl.scripting.BeansResolverFactory.containsKey(
   at org.activiti.engine.impl.scripting.ScriptBindings.containsKey(
   at javax.script.SimpleScriptContext.getAttributesScope(Unknown Source)
   at com.sun.script.javascript.ExternalScriptable.put(Unknown Source)
   at com.sun.script.javascript.RhinoScriptEngine.getRuntimeScope(Unknown Source)
   at com.sun.script.javascript.RhinoScriptEngine.eval(Unknown Source)
   at com.sun.script.javascript.RhinoScriptEngine.eval(Unknown Source)
   at javax.script.AbstractScriptEngine.eval(Unknown Source)

The line where the exception is thrown is (in :

return Context.getProcessEngineConfiguration().getBeans().containsKey(key);

And this is "Context.getProcessEngineConfiguration()" which returns "null". Here's the code of this part in '' :

public static ProcessEngineConfigurationImpl getProcessEngineConfiguration() {
     Stack<ProcessEngineConfigurationImpl> stack = getStack(processEngineConfigurationStackThreadLocal);
    if (stack.isEmpty()) {
      return null;
    return stack.peek();

Do you have any idea to perform this ?