简体   繁体   English

使用不同的类加载器加载类,以便在不需要时从JVM卸载它们

[英]loading classes with different classloaders to unload them from the JVM when not needed

In my application i'm using ServiceLoader to load modules(classes from .jar file) with different ClassLoaders in order to completely unload them when not needed from the context of the application and from the JVM itself. 在我的应用程序中,我使用ServiceLoader加载具有不同ClassLoader的模块(.jar文件中的类),以便在不需要时从应用程序上下文和JVM本身中完全卸载它们。 I know maybe is not a common topic "unload classes from JVM", there are some conditions for that to happen, so i am making the necessary effort. 我知道“从JVM卸载类”可能不是一个常见的话题,有一些条件可以实现,所以我正在做出必要的努力。 To make sure if all is working like expected i'm tracing the load and unload of classes with -XX:+TraceClassLoading and -XX:+TraceClassUnloading, the info from this parameters shows me that i can do a complete unload of any module from mi app and from the JVM itself (unload from the JVM happens during a complete GC). 为了确保所有工作都像预期的那样,我正在使用-XX:+ TraceClassLoading和-XX:+ TraceClassUnloading跟踪类的加载和卸载,此参数的信息显示了我可以从以下位置完全卸载任何模块mi应用程序以及从JVM本身(从JVM卸载在整个GC期间发生)。 All this seems to work fine... but my question is why the .jar files from where the module classes was loaded are keep open by the JVM?, that .jars cant be removed but the JVM says to have unloaded the classes from them. 所有这些似乎都可以正常工作...但是我的问题是,为什么从中加载模块类的.jar文件会由JVM保持打开状态?无法删除.jars,但JVM表示已从中卸载了这些类。 。 Obviously this is during JVM execution, but why keep open that .jar files if the JVM has no class loaded from them?, there is any thing i can do to force the JVM to free that .jar files? 显然,这是在JVM执行期间执行的,但是如果JVM没有从中加载类,为什么还要打开这些.jar文件?我有什么办法可以迫使JVM释放这些.jar文件?

Issue of the class load / unload should be deeply explored within different web containers. 应该在不同的Web容器内深入研究类加载/卸载的问题。

Some googling shows up that Tomcat 6.x has option antiJARLocking that option is used in Tomcat sources at http://svn.apache.org/repos/asf/tomcat/tc6.0.x/trunk/java/org/apache/catalina/loader/ 谷歌搜索显示Tomcat 6.x具有选项antiJAR锁定该选项已在Tomcat源中使用, 网址http://svn.apache.org/repos/asf/tomcat/tc6.0.x/trunk/java/org/apache/卡塔利娜/装载机/

Please read the sources and you will get sample of load / unload code there. 请阅读源代码,您将在那里获得加载/卸载代码的示例。

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

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