[
https://issues.apache.org/jira/browse/OLINGO-754?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=14908045#comment-14908045
]
Manuel Blechschmidt commented on OLINGO-754:
--------------------------------------------
Hi [~chandan.v.a],
I would say this is an anti pattern especially because it is never removed. If
somebody wants to access the ODataContext it should work via CDI
(http://hantsy.blogspot.de/2013/12/jpa-21-cdi-support.html).
{code}
public class PostListener {
@Inject
ODataContext oDataContext;
}
{code}
Further I removed the part of closing the entity manager with a dirty hack by
supplying own copies of the ODataJPAProcessor. Like I said I am using a full
Java EE server that manages this resource for me. If somebody closes the Entity
Manager other stateless session beans using this manager will throw exceptions.
The problem is not related due to the fact that the entity manager is not
closed. The problem is that the application server maintains a thread pool and
reuses threads.
Further details can be found in the following blog post:
http://shazsterblog.blogspot.de/2015/01/anti-pattern-threadlocal-variables-with.html
/Manuel
> MemoryLeak when using Olingo in Wildfly
> ---------------------------------------
>
> Key: OLINGO-754
> URL: https://issues.apache.org/jira/browse/OLINGO-754
> Project: Olingo
> Issue Type: Bug
> Components: odata2-jpa
> Affects Versions: V2 2.0.4
> Environment: java 8, wildfly 8.2, Linux
> Reporter: Manuel Blechschmidt
>
> The following code produces a memory leak in an application server:
> {code:title=org.apache.olingo.odata2.jpa.processor.core.ODataJPAContextImpl}
> @Override
> public void setODataContext(final ODataContext ctx) {
> odataContext = ctx;
> // This produces a memory leak on wildfly
> setContextInThreadLocal(odataContext);
> }
> {code}
> I removed the setContextInThreadLocal and it worked afterwards. I searched
> the whole code how this variable is normaly removed but was not able to find
> the clean way to solve this problem.
--
This message was sent by Atlassian JIRA
(v6.3.4#6332)