简体   繁体   English

从java逐步调用javascript

[英]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? 有没有办法以逐步的方式从java程序中执行java脚本?

I know how to call javascript from java. 我知道如何从java调用javascript。 I know about Rhino or Beanshell. 我知道Rhino或Beanshell。 No web server involved. 没有涉及Web服务器。

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. 我正在尝试实现的目标:让多个脚本由调度程序半并行执行,其中每个脚本每次都获得一个'tick',然后执行一个原子命令,就像在调试器中一样。 This should also 'step into' functions and for/while loops. 这也应该“进入”函数和/ while循环。

I need to call the script 'tick' at a specific time (and return immediately) so real threads are no use. 我需要在特定时间调用脚本'tick'(并立即返回),因此真正的线程是没用的。

So I guess i want a way to debug a script from within a java program without a debugger (and its overhead) involved. 所以我想我想要一种从java程序中调试脚本的方法,而不需要调试器(及其开销)。 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. 更具体地说,您需要一个可以在JVM上执行的JavaScript解释器。 Rhino seems to be the most popular one. 犀牛似乎是最受欢迎的。

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

If you are running scripts concurrently then you will need an interpreter for each concurrent script. 如果您同时运行脚本,那么每个并发脚本都需要一个解释器。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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