当我在Glassfish中部署/取消部署/重新部署JEE5应用程序时,如何自动触发Java函数来停止Quartz调度程序作业。
Implement ServletContextListener
and hook on contextDestroyed()
.
Basic example:
public class Config implements ServletContextListener {
public void contextInitialized(ServletContextEvent event) {
// Write code here which should be executed on webapp startup.
}
public void contextDestroyed(ServletContextEvent event) {
// Write code here which should be executed on webapp shutdown.
}
}
and register it as a <listener>
in web.xml
.
<listener>
<listener-class>com.example.Config</listener-class>
</listener>
Once you get to JAVA EE-6+, annotate a class with @WebListener and implement ServletContextListener on that class to get a shutdown notification. No need to deal with web.xml. See here
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.