简体   繁体   中英

Call a javascript from java step by step

Is there a way to execute a java script from within a java program in a step-by-step manner?

I know how to call javascript from java. I know about Rhino or Beanshell. No web server involved.

What I'm trying to achieve: Have multiple scripts execute semi concurrently scheduled by a scheduler where each script gets a 'tick' every now and then in which it executes one atomic command just like in a debugger. This should also 'step into' functions and for/while loops.

I need to call the script 'tick' at a specific time (and return immediately) so real threads are no use.

So I guess i want a way to debug a script from within a java program without a debugger (and its overhead) involved. Just stepwise execution is needed.

Any ideas?

Yes, it is possible by using an interpreter. More specifically, you need an JavaScript interpreter that can be executed on the JVM. Rhino seems to be the most popular one.

http://www.mozilla.org/rhino/

If you are running scripts concurrently then you will need an interpreter for each concurrent script.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM