Subj : How to use Rhino scopes in a multithreaded environment To : netscape.public.mozilla.jseng From : torntrousers Date : Sun Mar 06 2005 02:37 am I'm embedding Rhino in a multithreaded environment and I'm trying to understand how scopes work based on the info at http://www.mozilla.org/rhino/scopes.html I'd like to use a scope shared across threads which contains compiled function definitions, and for each thread to have its own scope for running calls to those functions. I'd also like to be able to add some custom objects to the thread specific scope for use by the function calls. The problem is the functions don't seem to find the objects I add to the thread specific scope. The following code demonstrates the problem: public class Test { public static void main(String[] args) { Context cx = Context.enter(); try { Scriptable sharedScope = cx.initStandardObjects(null, true); String script = "function foo() {out.println(\"in foo\");}"; Script compiledScript = cx.compileString(script,"bla",1,null); compiledScript.exec(cx, sharedScope); Function foo = (Function) sharedScope.get("foo", sharedScope); Scriptable scope = cx.newObject(sharedScope); scope.setPrototype(sharedScope); scope.setParentScope(null); Object wrappedOut = Context.javaToJS(System.out, scope); ScriptableObject.putProperty(scope, "out", wrappedOut); foo.call(cx, scope, scope, new Object[] {}); } finally { Context.exit(); } } } Running this fails with: Exception in thread "main" org.mozilla.javascript.EcmaError: ReferenceError: "out" is not defined. (bla#1) What am I doing wrong? I guess a supplementary question is is this a sensible approach to calling functions in a multithreaded environment in the most performant way? Thanks for any help. ...ant .