简体   繁体   中英

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.

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.

使用带有@PreDestroy方法的无状态 Bean

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM