开发者

CreateEntityManagerFactory is growing in size . Is it leaking memory?

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 apprec开发者_开发知识库iated.


I don't think you close either the EMF or the EM.

try {
        EntityManagerFactory emFactory = Persistence.createEntityManagerFactory("Auditing");
        em = emFactory.createEntityManager();
        // do whatever you need to do
        em.close();
        emFactory.close();
} catch (Exception ex) {
        throw new RuntimeException(ex.getMessage());
}

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 SoapMessageProcessor instances?

Are you using any kind of dependency injection framework? It'll make your life much simpler.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜