我在我的Java项目中使用eclipselink JPA
<persistence-unit name="...." transaction-type="JTA">
<provider>org.eclipse.persistence.jpa.PersistenceProvider</provider>
<mapping-file>META-INF/tm-mapping.xml</mapping-file>
<class>...</class>
<properties>
<property name="eclipselink.jdbc.batch-writing" value="Oracle-JDBC" />
<property name="eclipselink.jdbc.cache-statements" value="true" />
<property name="eclipselink.jdbc.native-sql" value="true" />
<property name="eclipselink.cache.size.default" value="1000" />
<property name="eclipselink.persistence-context.flush-mode" value="COMMIT" />
</properties>
</persistence-unit>
为了提高性能,我使用了flush-mode commit。但是当我给脚本提供更多数据时 我失去记忆,GC变得疯狂。 正如我在堆转储中看到的那样,插入的eclipse链接缓存太大了,所以当缓存很大时,可能有任何参数来刷新插入。
答案 0 :(得分:1)
如果您正在使用创建数千个对象的批处理,则需要确保JVM具有足够的内存来容纳所有对象。每个持久调用都要求EntityManager保留实体,直到它被释放。当EntityManager关闭,清除或实体被驱逐时会发生这种情况。
您可以每隔一段时间使用em.clear()强制清除缓存,并在此之前调用em.flush()以确保首先将更改推送到数据库。