[ 
https://issues.apache.org/jira/browse/CAMEL-7598?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=14073170#comment-14073170
 ] 

Daniel Seidewitz commented on CAMEL-7598:
-----------------------------------------

Yes, i think the correct patch would be to call clear after the flush. 

I've implemented this fix and we now don't see any rise in used heap on our 
production system (system is running since 2 days and was showing heap rises of 
100 MB / day before). 

{code}
Index: 
components/camel-jpa/src/main/java/org/apache/camel/component/jpa/JpaConsumer.java
IDEA additional info:
Subsystem: com.intellij.openapi.diff.impl.patch.CharsetEP
<+>UTF-8
===================================================================
--- 
components/camel-jpa/src/main/java/org/apache/camel/component/jpa/JpaConsumer.java
             (revision 89bf25387d3798620dc6972067e4a563e11f0b5a)
+++ 
components/camel-jpa/src/main/java/org/apache/camel/component/jpa/JpaConsumer.java
             (revision )
@@ -135,6 +135,7 @@
                 // commit
                 LOG.debug("Flushing EntityManager");
                 entityManager.flush();
+                entityManager.clear();
                 return messagePolled;
             }
         });
{code}

> Camel does not clear the jpa session after each processed message batch
> -----------------------------------------------------------------------
>
>                 Key: CAMEL-7598
>                 URL: https://issues.apache.org/jira/browse/CAMEL-7598
>             Project: Camel
>          Issue Type: Bug
>          Components: camel-jpa
>    Affects Versions: 2.12.3
>            Reporter: Daniel Seidewitz
>             Fix For: 2.13.3, 2.14.0
>
>
> We are using apache camel to poll from a database. As we want processed rows 
> only to be updated we have disabled consumeDelete on the JPA endpoint. 
> During testing we found a large memory leak: all polled entities are kept in 
> the session cache (we are using hibernate as persistence provider). 
> The issue seems to be in the JpaConsumer. In method poll() it calls 
> enitityManager.joinTransaction() at the beginning and entitiyManager.flush() 
> at the end of the method but it never calls  entityManager.clear(). As camel 
> is reusing the underlying session during each poll() this causes the first 
> level entity cache to grow indefinitely. 



--
This message was sent by Atlassian JIRA
(v6.2#6252)

Reply via email to