Subj : Re: Can I use Rhino in a servlet environment? To : Sam Cheung From : Igor Bukanov Date : Thu Apr 03 2003 02:06 am Sam Cheung wrote: > From Rhino documentation, it stores context information within the > current thread. Can I use Rhino in a servlet environment, since each > request for the SAME session may be given a DIFFERENT thread from the > thread pool in the application server? So how can I access the SAME > context for the SAME session given that requests for 1 session may be > served by different threads? You should not access/share Context between threads. It just store some runtime information and creation/initialization of new Context objects is very cheap. In your case you need to store a scope object which is an isntance of Scriptable inside you session. It works perfectly with Rhino and servelets. Here is a simple pattern to follow: When you need Context instance to pass to Rhino API, use: Context cx = Context.enter(); try { Use cx } finally { Context.exit(); } You can use ContextListener interface to customize Context instances. To initialize scope object for your session, use Scriptable scope = cx.initStandardObjects(null); which should happen of cause inside one of those try/finally for Context. You may also look at http://mozilla.org/rhino/scopes.html for more info. Regards, Igor .