How to use an ExecutorService with a JpaPersistModule ?

2015-05-13 Thread jbl
Hello, I'm relatively new to guice, and I've got a problem that I quite don't understand. I have a webapp based on guice, eclipse link, mysql that runs on a tomcat 7. The app uses a com.google.inject.persist.jpa.JpaPersistModule and a com.google.inject.persist.PersistFilter For some

Re: How to use an ExecutorService with a JpaPersistModule ?

2015-05-13 Thread Laszlo Ferenczi
Hi, I think the issue will be in the MyRunnable class. You create the MyRunnable instance in the http worker thread, if you simply inject an EntityManager there it'll be the one bound to the current thread (the http worker). After submitting it to a different thread you essentially leak the

Re: How to use an ExecutorService with a JpaPersistModule ?

2015-05-13 Thread Stephan Classen
First of all: guice-persist has some known bugs and they haven't been fixed for a long time. It looks like the extension is no longer maintained. Have a look into http://onami.apache.org/persist/ It is concepionally build on guice persist and migrating existing code should be very easy.

Re: How to use an ExecutorService with a JpaPersistModule ?

2015-05-13 Thread JB Lézoray
Hi Laszio,  Thank you for your answer.  I think you pinpointed the problem, and I'm a step forward in resolving it.  Here is the MyRunnable implementation, it already relies on two providers for  EntityManager and UnitOfWork. But now my question is : how to make sure that the 

Re: How to use an ExecutorService with a JpaPersistModule ?

2015-05-13 Thread Stephan Classen
The persist framework takes care that every thread has its own entity manager. So you don't need to do this. Calling unitOfWork.end() will close the entity manager for you. So also no need to do this manually. The unitOfWork is a singleton. So you can inject it directly and don't need to use

Re: How to use an ExecutorService with a JpaPersistModule ?

2015-05-13 Thread JB Lézoray
Hi Stephan, I followed your advices, and it seems that I don't have the error when I inject a UnitOfWork instead of a ProviderUnitOfWork.   As far as I understand it, if a MyRunnable gets executed by the ExecutorService  before the end of the MyServletWorker, then it receives a copy of the

Re: How to use an ExecutorService with a JpaPersistModule ?

2015-05-13 Thread Stephan Classen
Almost. UnitOfWork is in the singleton scope. This means there will exist exactly one instance for the entire injector. So it does not matter if you inject it directly or retrieve it from a provider. You will always recieve the very same (and only) instance. The EntityManager on the other