Hi there,

I'm trying to reduce the overhead of running JavaScript code. It looks like the best thing you can do is a) share a single engine, and b) reuse the script context.

I'm using a per-thread context like this:

    public static ScriptContext createJavaScriptContext() {
        ScriptContext context = new SimpleScriptContext();
        Bindings bindings = perThreadGlobalScope.get();
        if (bindings == null) {
            bindings = getJavaScriptEngine().createBindings();
            perThreadGlobalScope.set(bindings);
        } else
            bindings.clear();

        context.setBindings(bindings, ScriptContext.ENGINE_SCOPE);

        return context;
    }

Now I'm facing the problem that JavaScript variables are shared between different uses.
Ie. a:

    var found;
    print found;
    found = 1;

Would print "1" on the second run.

Is there a way to avoid this?

Bye,
   Axel.

Reply via email to