Spring调度程序关闭错误 [英] Spring scheduler shutdown error
本文介绍了Spring调度程序关闭错误的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
在tomcat容器中开发基于SPRING的调度程序期间,我总是在取消部署webapp或关闭服务器时获得此logoutput:
During development a SPRING based scheduler in a tomcat container, I always get this logoutput at undeploy webapp or shutdown server:
Apr 28, 2010 4:21:33 PM org.apache.catalina.core.StandardService stop
INFO: Stopping service Catalina
Apr 28, 2010 4:21:33 PM org.apache.catalina.loader.WebappClassLoader clearReferencesThreads
SEVERE: A web application appears to have started a thread named [org.springframework.scheduling.quartz.SchedulerFactoryBean#0_Worker-1] but has failed to stop it. This is very likely to create a memory leak.
Apr 28, 2010 4:21:33 PM org.apache.catalina.loader.WebappClassLoader clearReferencesThreads
SEVERE: A web application appears to have started a thread named [org.springframework.scheduling.quartz.SchedulerFactoryBean#0_Worker-2] but has failed to stop it. This is very likely to create a memory leak.
Apr 28, 2010 4:21:33 PM org.apache.catalina.loader.WebappClassLoader clearReferencesThreads
SEVERE: A web application appears to have started a thread named [org.springframework.scheduling.quartz.SchedulerFactoryBean#0_Worker-3] but has failed to stop it. This is very likely to create a memory leak.
Apr 28, 2010 4:21:33 PM org.apache.catalina.loader.WebappClassLoader clearReferencesThreads
SEVERE: A web application appears to have started a thread named [org.springframework.scheduling.quartz.SchedulerFactoryBean#0_Worker-4] but has failed to stop it. This is very likely to create a memory leak.
Apr 28, 2010 4:21:33 PM org.apache.catalina.loader.WebappClassLoader clearReferencesThreads
SEVERE: A web application appears to have started a thread named [org.springframework.scheduling.quartz.SchedulerFactoryBean#0_Worker-5] but has failed to stop it. This is very likely to create a memory leak.
.
.
.
SEVERE: A web application created a ThreadLocal with key of type [org.springframework.core.NamedThreadLocal] (value [Prototype beans currently in creation]) and a value of type [null] (value [null]) but failed to remove it when the web application was stopped. To prevent a memory leak, the ThreadLocal has been forcibly removed.
Apr 28, 2010 4:21:34 PM org.apache.coyote.http11.Http11Protocol destroy
INFO: Stopping Coyote HTTP/1.1 on http-8606
我该如何解决这个问题?
How can I fix this?
我将此监听器添加到我的webapp
I add this listener to my webapp
public class ShutDownHook implements ServletContextListener {
@Override
public void contextDestroyed(ServletContextEvent arg0) {
BeanFactory bf = (BeanFactory) ContextLoader.getCurrentWebApplicationContext();
if (bf instanceof ConfigurableApplicationContext) {
((ConfigurableApplicationContext)bf).close();
}
}
@Override
public void contextInitialized(ServletContextEvent arg0) {
}
}
和我的web.xml
and my web.xml
<listener>
<listener-class>pkg.utility.spring.ShutDownHook</listener-class>
</listener>
但错误仍然存在。
春季配置:
<bean id="run" class="org.springframework.scheduling.quartz.MethodInvokingJobDetailFactoryBean">
<property name="concurrent" value="false" />
<property name="targetObject" ref="scheduler" />
<property name="targetMethod" value="task" />
</bean>
<bean id="cronTrg" class="org.springframework.scheduling.quartz.CronTriggerBean">
<property name="jobDetail" ref="run" />
<property name="cronExpression" value="0/5 * * * * ?" />
</bean>
<bean class="org.springframework.scheduling.quartz.SchedulerFactoryBean" destroy-method="destroy">
<property name="triggers">
<list>
<ref bean="cronTrg" />
</list>
</property>
</bean>
推荐答案
您需要添加一个关闭钩子 - 请参阅在Spring 2.5中注册关闭挂钩。
You need to add a shutdown hook - see Registering a shutdown hook in Spring 2.5.
在您的情况下,您可能应该向webapp添加一个上下文监听器来执行此操作(监听器+实现类的web.xml条目)。
In your case, you probably should add a context listener to your webapp that does this (web.xml entry for the listener + implementing class).
使用close,这是最简单的。
Use close, it's easiest.
((YourClass)yourObject).close();
这篇关于Spring调度程序关闭错误的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文