Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

EJB application shutdown hook

How would i add a shutdown hook (just like the JVM Shutdown Hook) to listen (get notification) when an EJB application is deployed/undeployed (to stop the JMX MServerBean)?

I could use a ServletContextListener, unfortunately this an EJB jar.

like image 739
n002213f Avatar asked Sep 29 '11 19:09

n002213f


1 Answers

Use @Singleton bean and implement @PreDestroy:

@Startup
@Singleton
public class HookBean {

    @PreDestroy
    void wholeApplicationShuttingDown {
    }
}

UPDATE: Just noticed ejb-3.0 tag. @Singleton was added in 3.1. But still maybe you will find it useful.

like image 128
Tomasz Nurkiewicz Avatar answered Oct 02 '22 08:10

Tomasz Nurkiewicz