本文介绍了Java动态加载和卸载.java文件,垃圾回收?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在创建一个将运行很长一段时间的java应用程序,这需要更新的功能而不关闭。我决定提供这个更新的功能,以.java文件(从数据库中拉取为字节数组)的形式加载它们在内存中编译并实例化。如果你有一个更好的方式我所有的耳朵。



我遇到的问题是内存占用增加轻微加载这些脚本的每个周期,当我在人工环境中做一些测试。





但是,即使您为编译的类使用单独的类加载器,通过垃圾收集,因为类加载器和它加载的所有类都不符合垃圾收集,只要这些类的任何一个单一的实例被引用到任何其他地方(即你的应用程序的其余部分)。



这被称为,与应用程序服务器的常见问题,导致重新部署使用更多的内存,最终失败。诊断和修复类加载器泄漏可能非常棘手;该文章有所有的细节。


I am in the process of creating a java application that will be running for long periods of time which requires updated functionality without shutting down. I've decided to provide this updated functionality by loading it in the form of .java files (pulled as a byte array from a database) which are compiled in memory and instantiated. If you have a better way I am all ears.

The problem I have run in to is that memory footprint increases slightly with each cycle of loading these "scripts" when I do some testing in an artificial environment.

However, even if you use a separate classloader for your compiled classes, it can be tricky to get those classes to be picked up by garbage collection, because the classloader and all the classes it loaded are not eligible for garbage collcetion as long as a single instance of any of those classes is referred to anywhere else (i.e. the rest of your application).

This is known as a classloader leak and a common problem with appservers, causing redeployments to use ever more memory and eventually fail. Diagnosing and fixing a classloader leak can be very tricky; the article has all the details.

这篇关于Java动态加载和卸载.java文件,垃圾回收?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

08-20 02:42