Java 的 JavaScript 引擎 [英] JavaScript engine for Java

查看:28
本文介绍了Java 的 JavaScript 引擎的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

目前我在我的应用程序中使用 Rhino.我需要评估一些 JavaScript 蚂蚁从中获取值(我不需要通过 JavaScript 使用 Java 类).但它太慢了.也许有什么方法可以将 V8 与 Java 应用程序一起使用?

Currently I'm using Rhino in my application. I need to eval some JavaScript ant get values from it (I don't need to use Java classes through JavaScript). But it is too slow. Maybe there are any ways to use V8 with Java application?

更新:

我有大量不同类型的对象.我需要一个灵活的机制来验证和转换这些对象到所需的形式(用户应该能够更改验证和转换的规则(在运行时),即在 Java 中硬编码这些规则不合适).现在在 Rhino 上一切正常,但性能很差.我想过使用NodeJS,但似乎与它的通信,通过进程进行对象序列化等等——这些都会非常昂贵.

I have a large collection of objects of different types. I need a flexible mechanism for validation and transformation these objects to the required form (the user should be able to change the rules of validation and transformation (in runtime), ie hardcoding these rules in Java not suitable). Now everything works on Rhino, but performance is bad. I thought of using NodeJS, but it seems that communication with it, object serialization through processes, etc. - these all will cost very much.

推荐答案

  1. 绝对确定你真的需要eval吗?真正需要 eval 的地方非常非常少.

  1. Are you absolutely sure you really need eval? There are very, very few places where eval is actually necessary.

您可以使用 ProcessBuilder 用于对底层系统可用的任何进程进行 shell.我想说它比 Rhino eval 快的几率很低.

You can use ProcessBuilder to shell out to any process available to the underlying system. I'd say the odds of it being faster than a Rhino eval are low.

您可以让 NodeJS 进程与您通信的应用程序一起运行通过一个插座.可能在 Rhino 中使用 eval 赢得一场速度竞赛.

You might keep a NodeJS process running alongside your app which you communicate with via a socket. That might win a speed race with eval in Rhino.

如果您举例说明您实际想要实现的目标,那么人们可能会为您提出更好的方法.

If you give an example of what you're actually trying to achieve, it may be that people can come up with a better approach for you.

这篇关于Java 的 JavaScript 引擎的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆