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.
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.