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

℡╲_俬逩灬. 提交于 2019-12-12 02:21:32

问题


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. 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. 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). 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. 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?


回答1:


Issue of the class load / unload should be deeply explored within different web containers.

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/

Please read the sources and you will get sample of load / unload code there.



来源:https://stackoverflow.com/questions/7352739/loading-classes-with-different-classloaders-to-unload-them-from-the-jvm-when-not

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!