简体   繁体   English

来自 Java 的多个 Clojure 实例?

[英]Multiple Clojure instances from Java?

I'm trying to create a scripting language that compiles to Clojure, to then run it on the JVM.我正在尝试创建一种可以编译为 Clojure 的脚本语言,然后在 JVM 上运行它。 Each individual script, in the same JVM instance, but in an isolated manner.每个单独的脚本,在同一个 JVM 实例中,但以独立的方式。

Yet, when I see the implementation, I see the Clojure environment (namespaces and such) are global, so any alteration to the namespaces one script may make, affects following scripts.然而,当我看到实现时,我看到 Clojure 环境(命名空间等)是全局的,因此一个脚本可能对命名空间进行的任何更改都会影响后续脚本。

I wonder if there's a way to have multiple temporary, isolated, instances of a Clojure environment in just one JVM.我想知道是否有一种方法可以在一个 JVM 中拥有多个临时的、隔离的 Clojure 环境实例。 If not, which strategy could I use to avoid polluting global namespaces and potentially having a memory leak.如果没有,我可以使用哪种策略来避免污染全局命名空间并可能导致 memory 泄漏。

If you want to run scripts in an isolated manner, it would be advisable to use a separate classloader for each - regardless if it is clojure or any other kind of sandboxed code.如果您想以隔离的方式运行脚本,建议为每个脚本使用单独的类加载器 - 无论它是 clojure 还是任何其他类型的沙盒代码。

That will allow to have multiple implementations of the same namespace (ie packages).这将允许有相同命名空间(即包)的多个实现。

I'm not sure if the Clojure classloader will play along nicely with this though, so some experimentation is needed.我不确定 Clojure 类加载器是否能很好地配合这个,所以需要一些实验。

You also need to run with SecurityManager enabled and define policies that will prevent sandboxed code from accessing things like the file system, running processes, opening server sockets etc.您还需要在启用 SecurityManager 的情况下运行并定义策略,以防止沙盒代码访问文件系统、正在运行的进程、打开服务器 sockets 等内容。

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

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