本文介绍了Glassfish上的内存管理的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我的Glassfish服务器上运行了几个后台任务,这些服务由 @TimerService 实例实现。这些服务的目标是从文件中提取数据并将该数据插入到数据库中。

我最初尝试在JPA中执行此操作,但系统很容易停顿,现在我已将该流程转换为JDBC,这种响应更为灵敏。然而,在我无法确定的地方,仍然有大量的内存泄漏。

每个文件都是在管理自己的事务的方法中提取的(1个文件= 1个事务)。我认为一旦这个方法完成了所有变量的松散范围并被GC化,但事实并非如此。很短的时间后,我遇到了 OutOfMemoryException



我想知道Glassfish是否会,如何以及为何保持参考我的变量(这是非常重的对象)。我可以使用哪些设置或方法来最大限度地减少这些内存泄漏?



作为参考,我使用库存Glassfish设置进行了一些修改:

  -XX:+ CMSPermGenSweepingEnabled 
-XX:+ CMSClassUnloadingEnabled
-XX:MaxPermSize = 256m
-XmX1024m


解决方案

您可能正在处理类加载器泄漏。 JAXB可以在解组时解决这个问题。要确定你应该使用内存分析器。我强烈建议使用。只要按照一些教程,你应该能够弄清楚它。

I have several background tasks running on my Glassfish server implemented by @TimerService instances. The goal of these services is to extract data from files and insert that data into the database.

I tried initially to do this in JPA but the system stalled far to easily, I have now converted the process to JDBC which is far more responsive. However there are still enormous memory leaks somewhere along the way which I cannot pinpoint.

Each file is extracted in a method which manages its own transactions (1 file = 1 transaction). I would think that once this method finalises all variables loose scope and be GC'ed, but this is not the case. After a very short time I am experiencing OutOfMemoryException.

I am wondering if, how, and why Glassfish would be keeping reference to my variables (which are very heavy objects). What settings or methodologies can I apply to minimize these memory leaks?

For reference I am using the stock Glassfish settings with a couple of modifications :

-XX:+CMSPermGenSweepingEnabled 
-XX:+CMSClassUnloadingEnabled 
-XX:MaxPermSize=256m
–XmX1024m
解决方案

You might be dealing with a class loader leak. JAXB can do this when you're unmarshalling. To find out for sure you should use a memory analyzer. I highly recommend using the Eclipse Memory Analyzer Tool. Just follow a few of the tutorials and you should be able to get it figured out.

这篇关于Glassfish上的内存管理的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

10-23 02:36