1

In my project the code in the main method is like

jsEngine.eval(new FileReader(scrFile1));
jsEngine.eval(new FileReader(scrFile2));

I need to pass these files as threads. Is there any solutions for this problem??

musefan
  • 47,875
  • 21
  • 135
  • 185

1 Answers1

1

Are you using Rhino? Read What is the lifecycle and concurrency semantics of Rhino Script Engine first. Then, if you are OK with the two concurrent evals' effects visible in each other, do something along the lines of:

Thread t1 = new Thread(new Runnable() {
  public void run() {
    jsEngine.eval(new FileReader(scrFile1));
  }
});

Thread t2 = new Thread(new Runnable() {
  public void run() {
    jsEngine.eval(new FileReader(scrFile2));
  }
});

t1.start();
t2.start();
Community
  • 1
  • 1
Alexander Pavlov
  • 31,598
  • 5
  • 67
  • 93