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.
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.
Use a Stateless Bean with a @PreDestroy
method
@PreDestroy
on each instance. Since the OP wants to do something at shutdown, he needs a synchronized counter of SLSB instances and do the cleanup when it reaches 0. Rather inconvenient. –
Garamond @PreDestroy
method on non-lazy bean does the trick... Actually the @Singleton
and @Startup
annotations were introduced in EJB 3.1 exactly to solve the issue OP is having (there was no reliable startup callback as well...) –
Garamond © 2022 - 2024 — McMap. All rights reserved.