public class SoapMessageProcessor {
private EntityManager em;
private static final Logger logger = Logger.getLogger(SoapMessageProcessor.class);
public SoapMessageProcessor() {
try {
EntityManagerFactory emFactory = Persistence.createEntityManagerFactory("Auditing");
em = emFactory.createEntityManager();
} catch (Exception ex) {
throw new RuntimeException(ex.getMessage());
}
}
Will this leak memory, when this class is being invoked from a asynchronous EJB call?
So I thought of making the EntityManager and EntityManagerFactory static class members. Will that solve the issue?
Some help needed here. When I ran JProfiler. It says that this area is a Hot spot.Especially the createEntityManagerFactory.
Any help in fixing this leak is appreciated.
I don’t think you close either the EMF or the EM.
You shouldn’t keep an entity manager in a field. It’s kind of a “use once and then throw away” kind of object. You can, however, keep an EMF reference.
How often are you creating
SoapMessageProcessorinstances?Are you using any kind of dependency injection framework? It’ll make your life much simpler.