启动/停止 Tomcat 6.0.29 时出错

发布于 2024-10-27 17:01:18 字数 5699 浏览 4 评论 0原文

我在春天配置了一些调度程序。当我尝试启动我的Web应用程序时,它会抛出以下错误并停止。我的应用程序实际上并未启动。当我关闭tomcat时,我的调度程序看起来也像这样,一些石英线程没有关闭

<bean class="org.springframework.scheduling.quartz.SchedulerFactoryBean" destroy-method="destroy">
    <property name="triggers">
        <list>
           <ref bean="scheduler.localAdaptorCronTrigger"/>
        </list>
    </property>
</bean>   

<bean id="localAdaptor" class="LocalAdaptor" />

<bean id="scheduler.localFSSlaAdaptorJobDetail" class="org.springframework.scheduling.quartz.MethodInvokingJobDetailFactoryBean">
        <property name="targetObject" ref="Adaptor"/>
        <property name="targetMethod" value="xxxxxx"/>
</bean>

<bean id="scheduler.localAdaptorCronTrigger" class="org.springframework.scheduling.quartz.CronTriggerBean">
        <property name="jobDetail" ref="scheduler.localAdaptorJobDetail"/>
        <!-- run every morning at 12 AM -->
      <property name="cronExpression" value="0 0 0 * * ?"/>
    </bean>
    <bean id="scheduler.localFSSlaAdaptorSimpleTrigger" class="org.springframework.scheduling.quartz.SimpleTriggerBean">
        <!-- see the example of method invoking job above -->
        <property name="jobDetail" ref="scheduler.localAdaptorJobDetail"/>
        <!-- runs after 10 seconds for single time...-->
        <property name="startDelay" value="1000"/>
        <!-- repeated once -->
        <property name="repeatCount" value="0"/>
        <!-- useless as the repeat count is 0, so it will run once after 10 seconds of the startup of the application.... -->
        <property name="repeatInterval" value="60000"/>
</bean>

Stacktrace :

INFO: Closing Spring root WebApplicationContext
Mar 31, 2011 10:02:22 AM org.apache.catalina.loader.WebappClassLoader clearReferencesJdbc
SEVERE: The web application [/] registered the JBDC driver [com.mysql.jdbc.Driver] but failed to unregister it when the web application was stopped. To prevent a memory leak, the JDBC Driver has been forcibly unregistered.
Mar 31, 2011 10:02:22 AM org.apache.catalina.loader.WebappClassLoader clearReferencesThreads
SEVERE: The web application [/] appears to have started a thread named [Timer-0] but has failed to stop it. This is very likely to create a memory leak.
Mar 31, 2011 10:02:22 AM org.apache.catalina.loader.WebappClassLoader clearReferencesThreads
SEVERE: The web application [/] appears to have started a thread named [com.mchange.v2.async.ThreadPoolAsynchronousRunner$PoolThread-#0] but has failed to stop it. This is very likely to create a memory leak.
Mar 31, 2011 10:02:22 AM org.apache.catalina.loader.WebappClassLoader clearReferencesThreads
SEVERE: The web application [/c] appears to have started a thread named [com.mchange.v2.async.ThreadPoolAsynchronousRunner$PoolThread-#1] but has failed to stop it. This is very likely to create a memory leak.
Mar 31, 2011 10:02:22 AM org.apache.catalina.loader.WebappClassLoader clearReferencesThreads
SEVERE: The web application [/] appears to have started a thread named [com.mchange.v2.async.ThreadPoolAsynchronousRunner$PoolThread-#2] but has failed to stop it. This is very likely to create a memory leak.
Mar 31, 2011 10:02:22 AM org.apache.catalina.loader.WebappClassLoader clearThreadLocalMap
SEVERE: The web application [/] created a ThreadLocal with key of type [java.lang.ThreadLocal] (value [java.lang.ThreadLocal@71ee88dd]) and a value of type [org.apache.cxf.bus.CXFBusImpl] (value [org.apache.cxf.bus.CXFBusImpl@409468ca]) but failed to remove it when the web application was stopped. This is very likely to create a memory leak.

我实现了监听器:

import javax.servlet.ServletContext;
 import javax.servlet.ServletContextEvent;
 import javax.servlet.ServletContextListener;
 import org.quartz.SchedulerException;
 import org.quartz.impl.StdSchedulerFactory;
 import org.slf4j.Logger;
 import org.slf4j.LoggerFactory;


 public class QuartzServletContextListener implements ServletContextListener {

     final Logger log = LoggerFactory.getLogger(QuartzServletContextListener.class);
     public static final String QUARTZ_FACTORY_KEY =
             "org.quartz.impl.StdSchedulerFactory.KEY";
     private ServletContext ctx = null;
     private StdSchedulerFactory factory = null;

     public void contextInitialized(ServletContextEvent sce) {
         ctx = sce.getServletContext();

         try {

             factory = new StdSchedulerFactory();

             // Start the scheduler now

             factory.getScheduler().start();

             log.info("Storing QuartzScheduler Factory at"
                     + QUARTZ_FACTORY_KEY);

             ctx.setAttribute(QUARTZ_FACTORY_KEY, factory);

         } catch (Exception ex) {
             log.error("Quartz failed to initialize", ex);
         }
     }

     public void contextDestroyed(ServletContextEvent sce) {
         try {

             log.info("shutting down");
             factory.getScheduler().shutdown();
             Thread.sleep(1000);
         } catch (InterruptedException ex) {
             log.error("Quartz failed to shutdown", ex);
         } catch (SchedulerException ex) {
             log.error("Quartz failed to shutdown", ex);
         }
     }
 }

并在 web.xml 中添加了

<listener>
        <listener-class>xx.yy.QuartzServletContextListener</listener-class>
    </listener>

当我尝试使用 shutdown.sh 时,我可以看到仍然有一些线程处于活动状态并且 tomcat java 进程处于活动状态。

还要提一下,我有一些 3 到 4 个调度程序来处理上面在应用程序上下文中提到的不同工作。

I have configured some schedulers in spring.When i try to start my web application it throws following error and stops.My application is not actually started.My scheduler looks something like this also when i shut down tomcat some quartz thread are not shut down

<bean class="org.springframework.scheduling.quartz.SchedulerFactoryBean" destroy-method="destroy">
    <property name="triggers">
        <list>
           <ref bean="scheduler.localAdaptorCronTrigger"/>
        </list>
    </property>
</bean>   

<bean id="localAdaptor" class="LocalAdaptor" />

<bean id="scheduler.localFSSlaAdaptorJobDetail" class="org.springframework.scheduling.quartz.MethodInvokingJobDetailFactoryBean">
        <property name="targetObject" ref="Adaptor"/>
        <property name="targetMethod" value="xxxxxx"/>
</bean>

<bean id="scheduler.localAdaptorCronTrigger" class="org.springframework.scheduling.quartz.CronTriggerBean">
        <property name="jobDetail" ref="scheduler.localAdaptorJobDetail"/>
        <!-- run every morning at 12 AM -->
      <property name="cronExpression" value="0 0 0 * * ?"/>
    </bean>
    <bean id="scheduler.localFSSlaAdaptorSimpleTrigger" class="org.springframework.scheduling.quartz.SimpleTriggerBean">
        <!-- see the example of method invoking job above -->
        <property name="jobDetail" ref="scheduler.localAdaptorJobDetail"/>
        <!-- runs after 10 seconds for single time...-->
        <property name="startDelay" value="1000"/>
        <!-- repeated once -->
        <property name="repeatCount" value="0"/>
        <!-- useless as the repeat count is 0, so it will run once after 10 seconds of the startup of the application.... -->
        <property name="repeatInterval" value="60000"/>
</bean>

Stacktrace:

INFO: Closing Spring root WebApplicationContext
Mar 31, 2011 10:02:22 AM org.apache.catalina.loader.WebappClassLoader clearReferencesJdbc
SEVERE: The web application [/] registered the JBDC driver [com.mysql.jdbc.Driver] but failed to unregister it when the web application was stopped. To prevent a memory leak, the JDBC Driver has been forcibly unregistered.
Mar 31, 2011 10:02:22 AM org.apache.catalina.loader.WebappClassLoader clearReferencesThreads
SEVERE: The web application [/] appears to have started a thread named [Timer-0] but has failed to stop it. This is very likely to create a memory leak.
Mar 31, 2011 10:02:22 AM org.apache.catalina.loader.WebappClassLoader clearReferencesThreads
SEVERE: The web application [/] appears to have started a thread named [com.mchange.v2.async.ThreadPoolAsynchronousRunner$PoolThread-#0] but has failed to stop it. This is very likely to create a memory leak.
Mar 31, 2011 10:02:22 AM org.apache.catalina.loader.WebappClassLoader clearReferencesThreads
SEVERE: The web application [/c] appears to have started a thread named [com.mchange.v2.async.ThreadPoolAsynchronousRunner$PoolThread-#1] but has failed to stop it. This is very likely to create a memory leak.
Mar 31, 2011 10:02:22 AM org.apache.catalina.loader.WebappClassLoader clearReferencesThreads
SEVERE: The web application [/] appears to have started a thread named [com.mchange.v2.async.ThreadPoolAsynchronousRunner$PoolThread-#2] but has failed to stop it. This is very likely to create a memory leak.
Mar 31, 2011 10:02:22 AM org.apache.catalina.loader.WebappClassLoader clearThreadLocalMap
SEVERE: The web application [/] created a ThreadLocal with key of type [java.lang.ThreadLocal] (value [java.lang.ThreadLocal@71ee88dd]) and a value of type [org.apache.cxf.bus.CXFBusImpl] (value [org.apache.cxf.bus.CXFBusImpl@409468ca]) but failed to remove it when the web application was stopped. This is very likely to create a memory leak.

I implemented listener:

import javax.servlet.ServletContext;
 import javax.servlet.ServletContextEvent;
 import javax.servlet.ServletContextListener;
 import org.quartz.SchedulerException;
 import org.quartz.impl.StdSchedulerFactory;
 import org.slf4j.Logger;
 import org.slf4j.LoggerFactory;


 public class QuartzServletContextListener implements ServletContextListener {

     final Logger log = LoggerFactory.getLogger(QuartzServletContextListener.class);
     public static final String QUARTZ_FACTORY_KEY =
             "org.quartz.impl.StdSchedulerFactory.KEY";
     private ServletContext ctx = null;
     private StdSchedulerFactory factory = null;

     public void contextInitialized(ServletContextEvent sce) {
         ctx = sce.getServletContext();

         try {

             factory = new StdSchedulerFactory();

             // Start the scheduler now

             factory.getScheduler().start();

             log.info("Storing QuartzScheduler Factory at"
                     + QUARTZ_FACTORY_KEY);

             ctx.setAttribute(QUARTZ_FACTORY_KEY, factory);

         } catch (Exception ex) {
             log.error("Quartz failed to initialize", ex);
         }
     }

     public void contextDestroyed(ServletContextEvent sce) {
         try {

             log.info("shutting down");
             factory.getScheduler().shutdown();
             Thread.sleep(1000);
         } catch (InterruptedException ex) {
             log.error("Quartz failed to shutdown", ex);
         } catch (SchedulerException ex) {
             log.error("Quartz failed to shutdown", ex);
         }
     }
 }

And added in web.xml

<listener>
        <listener-class>xx.yy.QuartzServletContextListener</listener-class>
    </listener>

When I try to use shutdown.sh I can se still some threads active and tomcat java process active .

Also to mention I have some 3 to 4 schedulers for different job as mentioned above in application context.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(3

天暗了我发光 2024-11-03 17:01:18

至于 Tomcat 报告的任何 Quartz 相关资源,这是因为当 Quartz 需要几毫秒以上的时间来关闭其资源时,Tomcat 过于急于寻找未释放的资源。

请参阅此处的讨论(以及简单的解决方法):

http://forums。 terracotta.org/forums/posts/list/3479.page

As for any Quartz-related resources being reported by Tomcat, this is due to Tomcat being a bit over-eager at looking for non-freed resources when Quartz takes more than a few milliseconds to shutdown its resources.

See discussion here (along with a simple work-around):

http://forums.terracotta.org/forums/posts/list/3479.page

╄→承喏 2024-11-03 17:01:18

这不是问题。 Tomcat 会自动删除不需要的线程和线程局部变量,但只是告诉您您的代码或库正在做一些“有风险”的事情。

您可能想要向相应的库(c3p0 和 CXF)报告问题,它们应该在关闭时进行清理。

It's not a problem. Tomcat automatically removes the unwanted threads and threadlocals, but just tells you that your code or libraries are doing something "risky".

You may want to report issues to the respective libraries (c3p0 and CXF) that they should cleanup on shutdown.

遗弃M 2024-11-03 17:01:18

确保线程终止的唯一方法是中断并加入它们。

这可以通过实现 org.quartz.InterruptableJob 来完成,如问题 如何防止quartz 中的内存泄漏[?]

The only way to ensure that threads are terminated, is to interrupt and join them.

This can by done by implementing org.quartz.InterruptableJob, as described in the answer to the question How to prevent a memory leak in quartz [?].

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文