Sign In : Sign Up : Blog : Search: Language : Help :
This website is now frozen, please migrate your content to BotLibre.com or BotLibre.biz
Java Persistence Performance : Bulk inserts cause OOM even if done in batches

RE: Bulk inserts cause OOM even if done in batches

by jamesssss posted Nov 27 2014, 5:45

The root of your problem is that something is holding onto the old EntityManagers. After the end of the transaction the container should be releasing references to them and they should be free to garbage collect, so it should not matter what they reference.

Ensure that nothing in your app references any of the entity objects, as they can hold a reference to their entity manager and prevent gc. Also what is the @Yam annotation, check that it is not holding a reference. Try using a memory profiler to determine what is holding onto the objects.

Your em.clear() after the commit will do nothing, as for a JTA managed EntityManager you will get a new EntityManager after the end of the transaction, so calling em.clear() after commit will only create a new EntityManager.

You can clear the EntityManager before the commit by first calling flush.

That should resolve your issue, but you should find the root of what is holding onto your EntityManagers.

Id: 326301
Posted: Nov 27 2014, 5:45
Replies: 0
Views: 1741, today: 2, week: 3, month: 15
I'm sure
Flag graphic as offensive, or in violation of site rules