Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6983925
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 27, 20262026-05-27T18:28:58+00:00 2026-05-27T18:28:58+00:00

I am interested in the lifecycle and concurrency semantics of (Rhino) Script Engine and

  • 0

I am interested in the lifecycle and concurrency semantics of (Rhino) Script Engine and associated classes. Specifically:

  1. Is Bindings supposed to be thread safe?
  2. Should multiple threads be allowed to share a single ScriptEngine instance?
  3. … or should each thread construct a short-lived instance?
  4. … or keep them in a pool?
  5. What happens if multiple threads concurrently call ScriptEngine.eval(...)?
  6. Same questions for CompiledScript instances
  7. Same questions for interface implementations generated using Invocable.getInterface(...)?
  8. Presumably, objects placed in Bindings follow Java’s garbage collection. What about garbage collection of objects that don’t end up in the bindings?
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-27T18:28:58+00:00Added an answer on May 27, 2026 at 6:28 pm

    So I’ve run the experiment and the Rhino engine reports “Mozilla Rhino” is MULTITHREADED which the JavaDocs asserts

    “MULTITHREADED” – The engine implementation is internally thread-safe
    and scripts may execute concurrently although effects of script
    execution on one thread may be visible to scripts on other threads.”

    Here’s the code…it looks threadsafe to me, as long as the bindings you pass in are threadsafe too.

    package org.rekdev;
    import java.util.*;
    import javax.script.*;
    public class JavaScriptWTF {
        public static void main( String[] args ) {
            ScriptEngineManager mgr = new ScriptEngineManager();
            List<ScriptEngineFactory> factories = mgr.getEngineFactories();
            for ( ScriptEngineFactory factory : factories ) {
                System.out.println( String.format(
                        "engineName: %s, THREADING: %s",
                        factory.getEngineName(),
                        factory.getParameter( "THREADING" ) ) );
            }
        }
    }
    

    …the output is…

    engineName: AppleScriptEngine, THREADING: null
    engineName: Mozilla Rhino, THREADING: MULTITHREADED

    To answer your exact question…

    1. Is Bindings supposed to be thread safe?
      It sounds to me that it is your responsibility to make them Thread-safe. In other words, pass in only immutable objects and whether the engine is Thread-safe or not becomes a non-issue.

    2. Should multiple threads be allowed to share a single ScriptEngine instance?
      It sounds to me like they can, but the key is the state sharing that can occur through the Bindings. Immutable objects are your friend.

    3. …or should each thread construct a short-lived instance?
      It seems to me that the best way to think of this is that each execution of eval is a short lived instance.

    4. … or keep them in a pool?
      In this day and age attempting to pool resources on your own is rarely a good idea. Give the short-lived instance a shot, measure its performance, and work out from there.

    5. What happens if multiple threads concurrently call ScriptEngine.eval(…)?
      If I understand the Rhino engine’s repsonse to MULTITHREADING correctly, ScriptEngine.eval should be fine with concurrent calls.

    6. Same question for CompiledScript instances
      The JavaDocs state that “Changes in the state of the ScriptEngine caused by execution of the CompiledScript may visible during subsequent executions of scripts by the engine.” http://docs.oracle.com/javase/6/docs/api/javax/script/CompiledScript.html. So they don’t sound Thread-safe at all in an environment where you appear to be trying to minimize the number of ScriptEngine instances.

    7. Same questions for interface implementations generated using Invocable.getInterface(…)?
      You are on your own here. I don’t understand exactly why or when this capability would be used and it sounds to me like you may be “jumping the shark” here. If you want to go this deep into the scripting language, I recommend that you abandon JavaScript and look at Groovy for a more scriptable Java.

    8. Presumably, objects placed in Bindings follow Java’s garbage collection. What about garbage collection of objects that don’t end up in the bindings?
      If they don’t end up in bindings I expect them to be bound to the ScriptEngine and follow its lifecycle (based upon the docs that I have read). Pooling the ScriptEngine instances does not sound like a great idea.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm interested if anyone knows exactly how effective/safe/protected PHP's bcompiler is against reverse engineering.
Interested in using libxml2dom in a Python script of mine to (obviously) parse some
Interested if anyone has used VSTS Database Edition extensively and, if so, which features
Im interested in doing some matrix calculations in objective-C (for an iPhone app). A
im interested how many api calls per second or per minute i can do
I'm interested in using the html5 notifications api but have a few questions: Is
I am always interested in knowing what browsers support what and which are more
I'm just interested in the best approach to the following... I have an app
I'm interested in doing something like this: public interface Foo { public static abstract
I am interested in creating a simple HLS Viewer for the Xbox 360 that

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.