当我运行Tomcat7时,我得到这个错误消息:
Aug 04, 2015 12:53:47 PM org.apache.catalina.loader.WebappClassLoader clearReferencesThreads
SEVERE: The web application [/sample] appears to have started a thread named [org.springframework.scheduling.quartz.SchedulerFactoryBean#5_Worker-9] but has failed to stop it. This is very likely to create a memory leak.发布于 2015-12-04 18:16:08
您应该像下面这样在ServletContextListener中优雅地关闭quartz:
public class AppListener implements ServletContextListener
{
@Override
public void contextDestroyed(ServletContextEvent arg0)
{
try
{
WebApplicationContext context = ContextLoader.getCurrentWebApplicationContext();
Scheduler scheduler = (Scheduler) context.getBean("quartzSchedulerFactory");
scheduler.shutdown(true);
}
catch (Exception e)
{
e.printStackTrace();
}
}
@Override
public void contextInitialized(ServletContextEvent arg0)
{
} 您必须在web.xml中添加这些ServletContextListener。您应该将侦听器放在web.xml中的第一个位置,因为on tomcat在关机时以相反的顺序运行侦听器。
<listener>
<listener-class>yourpackage.AppListener</listener-class>
</listener>或者,您可以在带有@PreDestroy注释的方法中关闭调度程序
发布于 2021-04-30 06:24:51
至少从Spring3.0开始,SchedulerFactoryBean就有了一个标志来告诉它等待作业完成。设置标志并确保在关机时调用销毁方法:
<bean id="scheduler"
class="org.springframework.scheduling.quartz.SchedulerFactoryBean"
destroy-method="destroy">
<property name="waitForJobsToCompleteOnShutdown" value="true" />
....https://stackoverflow.com/questions/31807464
复制相似问题