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 8047647
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 5, 20262026-06-05T06:10:15+00:00 2026-06-05T06:10:15+00:00

how to use a single Java ScriptEngine to perform multiple evaluation synchronously? for example

  • 0

how to use a single Java ScriptEngine to perform multiple evaluation synchronously?

for example

method1 includes

sce.eval(code1);

method2 includes

sce.eval(code2);

then the evaluations ran concurrently if both methods synchronized

  • 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-06-05T06:10:16+00:00Added an answer on June 5, 2026 at 6:10 am

    Synchronized and concurently doesn’t fit together as one is the opposite of the other. If the eval method is synchronized you need 2 instances of the scriptengine with the same context, if it is not here comes an explanation on doing parallel/concurrent execufion.

    If you want to run both method concurrently, you need more than one thread running as a single thread will sequentially run through it’s execution pipeline.

    Synchronized means it is thread safe and will queue all the calls made to any synchronized method of a class. For example, if m1 and m2 are synchronized, thread1 calls m1 and thread2 calls m2, the first one that will reach their respctive method will run correctly ehile the second one will wait ’til the other has exit (not totally true) the method to execute the inner code of it’s method..

    Now, you can take a look at the class Thread, ExecutorService and Executors if you want to run multiple threada at the same time and each will run it’s own pipeline/execution atack.

    Finally if you want both thread to share the same script engine, you’ll have to use the same reference of that object, best way by providing it to the constructor of your object.

    But, this is where problems occurs. If the script engine doesn’t handle concurrency well, this might lead to some obscur weird behavior so you’ll have to read the spec of the scrupt engine and validate if the implementation you are using is thread safe (hence concurrently execution safe).

    Simple example :

    public void launchAsync(final String code) {
       new Thread() {
           public void run() {
               engine.eval(code);
           }
       }.run();
    }
    

    This will execute the code asynchronously than the main thread meaning that calling the method twice will run them in parallel (in a different thread than this one).

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

Sidebar

Related Questions

For example, Java Swing and Android UI both use a single threaded model where
I want to use a single Doctrine install on our server and serve multiple
I have a java web application running on tomcat, and will use single sign
I need a byte buffer class in Java for single-threaded use. The buffer should
I need a byte buffer class in Java for single-threaded use. I should be
I'm trying to use javadoc to document one single java file on window 7,to
I try to use single quotes as much as possible and I've noticed that
Currently I use a single equation with different combination of known/unknown parameters. As I
I want to use a single font named Algerian across my whole website. So,
If I import and use a single class from another package, will it include

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.