从JVM线程本地空间卸载Clojure变量 [英] Unloading Clojure vars from JVM thread-local space

查看:66
本文介绍了从JVM线程本地空间卸载Clojure变量的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在Clojure中编写一个用于BaseX的插件,通过lein uberjar构建,包含Clojure解释器。在大多数情况下,这很好。

I'm writing a plugin for BaseX in Clojure, built via "lein uberjar" with the Clojure interpreter included. For the most part, this works well.

然而 - 当通过BaseX HTTP实例运行时,评估发生在Jetty的线程池中,而不是线程抛出后

However -- when running via the BaseX HTTP instance, evaluation takes place inside Jetty's thread pool rather than having threads thrown away after a client disconnects.

由于加载插件通过自定义类加载器加载Clojure的类,并抛弃作为插件入口点的(AOT编译的)对象实例,丢弃Clojure在线程本地空间中放置的变量,一个类加载器泄漏导致PermGen空间最终被Clojure解释器的多个实例耗尽。

As loading the plugin loads Clojure's classes through a custom classloader, and throwing away the (AOT-compiled) object instance which acts as the plugin's entry point does not discard the vars placed by Clojure in thread-local space, a classloader leak results with PermGen space being eventually exhausted by multiple instances of the Clojure interpreter.

如何解决?

推荐答案

这个想法可能(或者)可能不会)工作:

This idea might (or might not) work:


  1. 不要做一个uberjar,保持Clojure jar分开;

  1. Don't make an uberjar, keep Clojure jars separate;

通过将Clojure jar放入BaseX的主类路径(编辑启动BasexX服务器的命令行,类似 java -cp BaseX.jar) ; clojure.jar org.basex.BaseXServer );

push Clojure jars up the classloader hierarchy by putting them into the main classpath of BaseX (edit the command line that starts BasexX server, something like java -cp BaseX.jar;clojure.jar org.basex.BaseXServer);

将插件打包成一个jar包,在

Package your plugin as a jar with just your code in it and rely on the Clojure classes already present in the main classpath.

这篇关于从JVM线程本地空间卸载Clojure变量的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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