简体   繁体   中英

Multiple Clojure instances from Java?

I'm trying to create a scripting language that compiles to Clojure, to then run it on the JVM. Each individual script, in the same JVM instance, but in an isolated manner.

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.

I wonder if there's a way to have multiple temporary, isolated, instances of a Clojure environment in just one JVM. If not, which strategy could I use to avoid polluting global namespaces and potentially having a memory leak.

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.

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.

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.

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