如何防止Eclipselink占用高速缓存中的所有内存? [英] How can I prevent Eclipselink from consuming all memory with the cache?

查看:119
本文介绍了如何防止Eclipselink占用高速缓存中的所有内存?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我的应用程序提取了大量的几何数据.我使用Eclipselink 2.4.1将数据持久保存在MySQL数据库中.该应用程序以批处理方式工作,即我收集了一组数据,然后将其保存,然后继续下一组数据,将其保存,依此类推.另一个应用程序后来读取该数据并进行处理,但是这个问题仅与第一个收集数据的应用程序有关.

My application extracts large amounts of geometry data. I use Eclipselink 2.4.1 to persist that data in a MySQL database. The application works batch-style, i.e. I gather a set of data, then persist it, and continue with the next set, persist it and so on. Another application later reads that data and processes it, but this question is only about the first application that gathers the data.

数据收集应用程序运行了相当长的时间.我使用一组固定的EntityManagers,它们在启动时创建并实时运行,直到应用程序完成.提取是多线程的,每个线程只有一个EntityManager.我的问题是,无论我如何配置缓存,一段时间后EclipseLink都会消耗掉所有内存,而一段时间后我得到一个OutOfMemoryError.

The data-gathering application runs for quite some time. I use a fixed set of EntityManagers which are created at startup and live until the application is finished. Extraction is multithreaded and there is one EntityManager per Thread. My problem is that no matter how I configure the cache, after a while EclipseLink eats up all the memory and after a while I get an OutOfMemoryError.

我使用VisualVM提取了堆转储,然后使用Eclipse Memory Analyzer分析了堆转储. EntityManagerImpl.extendedPersistenceContext.cloneMapping保留了可疑的内存量.该地图包含对我的几何数据对象的引用.随着时间的流逝,此映射的大小会达到数百兆字节,这就是导致内存不足错误的原因.

I used VisualVM to extract heap dumps which I analyzed using Eclipse Memory Analyzer. A suspicious amount of memory is held by EntityManagerImpl.extendedPersistenceContext.cloneMapping. This map holds references to my geometry data objects. Over time, this map gets hundreds of megabytes in size and that's what causes the out of memory error.

我已经尝试了以下方法:

I have already tried the following:

  • 我通过配置eclipselink.persistence-context.reference-mode=weak使用弱引用.我已验证EntityManagerImpl.extendedPersistenceContext.cloneMapping的类型为IdentityWeakHashMap.从有关弱缓存的文档中,我希望参考模式weak解决了该问题.不幸的是,垃圾收集器仍然没有声明这些条目,而且我一直走出内存不足的错误.
  • 我试图用eclipselink.cache.shared.default=false完全关闭缓存.问题仍然存在.
  • I use weak references by configuring eclipselink.persistence-context.reference-mode=weak. I have verified that EntityManagerImpl.extendedPersistenceContext.cloneMapping is of type IdentityWeakHashMap. From the documentation about weak caches I would expect that using reference mode weak solves the problem. Unfortunately, the garbage collector still does not claim the entries and I keep getting out of memory errors.
  • I tried to turn off caching completely with eclipselink.cache.shared.default=false. The problem persists.

有人对这里发生的事情以及我如何解决该问题有建议吗?我也欢迎提出建议来解决该问题.

Does anybody have a suggestion as to what's going on here and how I could solve that problem? I'm also open to suggestions how to circumvent the problem.

推荐答案

一些事情.

首先,您不应保留寿命长的EntityManager.您应该为每个交易或每个请求创建一个新的EntityManger.

First, you should not keep long lived EntityManagers. You should create a new EntityManger per transaction, or per request.

第二,确保您的应用程序(静态变量等)没有保存对对象的引用,如果有任何引用在引用该对象,则不会进行垃圾收集.

Second, ensure you application (static variables, etc.) is not holding references to the objects, if anything is referencing the object it will not garbage collect.

这篇关于如何防止Eclipselink占用高速缓存中的所有内存?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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