1

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.

iriiko
  • 43
  • 4
  • 1
    It's possibly a bug. If you have a simple reproducer, I would raise an issue on Github: https://github.com/payara/Payara/issues – OndroMih Feb 25 '20 at 09:46

1 Answers1

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.

Christoph John
  • 3,003
  • 2
  • 13
  • 23
  • I'm using @Singleton and "@ApplicationScoped". "@WebListener" is working. Thanks. I also tried a classic Runtime.getRuntime().addShutdowHook() that works too but no more Java EE compliant. – iriiko Feb 25 '20 at 09:41
  • Yes, I would also not use the shutdownHook inside a managed environment. Glad that `@WebListener` worked. If the answer was helpful please consider upvoting and/or accepting it. You still have other questions in your post but I'd suggest to open a separate question for this if they still are relevant. – Christoph John Feb 25 '20 at 09:46