You are pretty much right on track, it is safe to share scriptable objects between contexts. The context is just an execution environment, it can execute code in any scope. It is irrelevant where that scope was originally created.
For example, I work with a case where I create many scopes, each with a single long running script running under it, but I only execute a small portion of the code in any one cycle. I have many worker threads that each take the next scope in the queue and execute a small portion of the accompanying script, then put it back on the queue for another thread to handle in the next cycle. You're case is similar. In fact, if everything truly is read only you can even run all of your scripts within one scope (I don't know of any issue with that, but if someone else with more knowledge does they will probably speak up). After all, a scope is nothing more than a set of objects available to the javascript code while it executes, so multiple scripts can execute using that same set of objects, even simultaneously as long as concurrency is taken care of - in your case, by maintaining static data. A word on concurrency though - if any data in the scope *does* change at runtime you need to consider concurrency and at a minimum make the mutable data volatile. Dave -----Original Message----- From: dev-tech-js-engine-rhino-bounces+davidparks21=yahoo....@lists.mozilla.org [mailto:dev-tech-js-engine-rhino-bounces+davidparks21=yahoo....@lists.mozill a.org] On Behalf Of Brad Baker Sent: Tuesday, August 04, 2009 7:04 PM To: [email protected] Subject: Re: a question of contexts and scopes Is it therefore safe to share Scriptable objects between Contexts when they have the same top level scope? My use case is a little rules engine where at startup I evaluate the "rules.js" and capture the resultant rules object as a ScriptableObject. Then for every web request (eg each in its own thread) I want to "evalutate" JS Functions from the original "ruleset" scriptable object. It will be a in a read only manner. Predefined rules are only ever evaluated in my case. There are only ever true of a given read only piece of input. I gather I would do a Context.enter()/exit() for each web request thread and also create a new scope object for each thread but is it safe to "execute" functions on a Scrtiptable that was created in another thread and with another parent scope? Cheers Brad Baker Atlassian _______________________________________________ dev-tech-js-engine-rhino mailing list [email protected] https://lists.mozilla.org/listinfo/dev-tech-js-engine-rhino _______________________________________________ dev-tech-js-engine-rhino mailing list [email protected] https://lists.mozilla.org/listinfo/dev-tech-js-engine-rhino
