PayaraMicro does not call @PreDestroy on EJB or ApplicationScoped

怎甘沉沦 提交于 2020-05-31 05:43:28

问题


I'm migrating a WAR application from PayaraServer to Payara Micro to reduce RAM usage.

I just realise that @PreDestroy on EJBs are not called when stopping the instance with CTRL+C.

Is there a correct way to close the payaramicro instance properly as I'd like to execute some operations.

Thanks for your answers!

Or which services in Payara Server to deactivate to use as much as RAM as PayaraMicro?

I'm using the version 5.183, and I also tried the 5.192.


回答1:


Which kind of EJB did you use? In my opinion it should work on @Singleton and @Stateless. I am not sure how the other EJBs are supported by Payara Micro.

However, since Payara Micro supports the Java EE Web Profile and you are using a web application anyway, I would suggest to use a @WebListener to get notified of lifecycle events.

It could be implemented as follows:

import javax.servlet.ServletContextEvent;
import javax.servlet.ServletContextListener;
import javax.servlet.annotation.WebListener;

@WebListener
public class ContextListener implements ServletContextListener {

    @Override
    public void contextInitialized(ServletContextEvent event) {
        // do needed setup work here
    }

    @Override
    public void contextDestroyed(ServletContextEvent event) {
        // do your cleanup actions here
    }
}

Simply add this class to your WAR file then.



来源:https://stackoverflow.com/questions/60381558/payaramicro-does-not-call-predestroy-on-ejb-or-applicationscoped

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!