Hi,
I've continued a bit with my
"JTA Application managed entity manager" and faced another problem. It seams that the using of the
joinTransaction() api has a memory leak.
Let me explain...
I've wrote an interceptor around stateless session bean methods that injects an EntityManager dynamically. If the EntityManager already exists in the retreived session instance (from the AS pool), I don't create the EntityManager, the only thing I do is calling the
joinTransaction() method to associate the bean current transaction with the current EntityManager.
The thing is that this method is called each time a session bean method is called (the way it should be using an interceptor, right ?), but my test suite gets slower and slower the more the
joinTransaction() method is performed.
here is the interceptor code:
Code:
@AroundInvoke
public Object entityManagerSelectionInterceptor (InvocationContext invocationCtx)
throws Exception {
if (entityManager == null) {
// try to get the EM from the cache
String userLogin = this.getClass ().getName ();
if ((entityManager = this.entityManagers.get (userLogin)) == null) {
// this code is performed only once
// since the bean instance is alive in the pool
entityManager = buildEntityManager (userLogin);
// put in cache
entityManagers.put (userLogin, entityManager);
}
}
// performed each time a session bean method is called
entityManager.joinTransaction ();
return invocationCtx.proceed ();
}
here are the benches:
test suite: 73,289 seconds
test suite: 79,913 seconds
test suite: 95,564 seconds
test suite: 116,339 seconds
test suite: 122,618 seconds
test suite: 126,991 seconds
test suite: 141,097 seconds
Is it possible that the EntityManager keeps ALL the transaction objects it is attached to and never releases them ?