开发者社区> 问答> 正文

java Quartz 内存泄漏问题

我用定时器启动应用的时候发现内存泄漏,具体报错如下:

十月 30, 2015 2:30:12 下午 org.apache.catalina.startup.HostConfig undeploy
信息: Undeploying context [/ChinaMoney Maven Webapp]
十月 30, 2015 2:30:15 下午 org.apache.catalina.loader.WebappClassLoader clearReferencesJdbc
严重: The web application [/ChinaMoney Maven Webapp] registered the JDBC driver [net.sourceforge.jtds.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.
十月 30, 2015 2:30:15 下午 org.apache.catalina.loader.WebappClassLoader clearReferencesThreads
严重: The web application [/ChinaMoney Maven Webapp] appears to have started a thread named [startQuertz_Worker-1] but has failed to stop it. This is very likely to create a memory leak.
十月 30, 2015 2:30:15 下午 org.apache.catalina.loader.WebappClassLoader clearReferencesThreads
严重: The web application [/ChinaMoney Maven Webapp] appears to have started a thread named [startQuertz_Worker-2] but has failed to stop it. This is very likely to create a memory leak.
...

定时器定义如下:

<!-- 定义触发时间 -->
        <bean id="doTimeSync" class="org.springframework.scheduling.quartz.CronTriggerFactoryBean">
            <property name="jobDetail">
                <ref bean="jobtaskSync" />
            </property>
            <property name="cronExpression">
                <value>30 38 09 * * ?</value>
            </property>
        </bean>
        <!-- 总管理类 如果将lazy-init='false'那么容器启动就会执行调度程序 -->
        <bean id="startQuertz" lazy-init="false" autowire="no"
            class="org.springframework.scheduling.quartz.SchedulerFactoryBean">
            <property name="triggers">
                <list>
                    <ref bean="doTimeSync" />
                </list>
            </property>
             <property name="quartzProperties">  
                <props>  
                    <prop key="org.quartz.scheduler.instanceName">buy_it_now</prop>
                    <prop key="org.quartz.threadPool.threadCount">2</prop>  
                    <prop key="org.quartz.plugin.shutdownhook.class">org.quartz.plugins.management.ShutdownHookPlugin</prop>
                    <prop key="org.quartz.plugin.shutdownhook.cleanShutdown">true</prop>
                    <prop key="org.quartz.threadPool.threadsInheritContextClassLoaderOfInitializingThread">true</prop>
                </props>  
            </property>
        </bean>

1
2
3

展开
收起
蛮大人123 2016-03-06 10:04:53 6351 0
1 条回答
写回答
取消 提交回答
  • 我说我不帅他们就打我,还说我虚伪
    public void contextDestroyed(ServletContextEvent sce)  { 
            // 卸载JDBC驱动
            Enumeration<Driver> drivers =  DriverManager.getDrivers();
            while(drivers.hasMoreElements()){
                try {
                    Driver driver = drivers.nextElement();
                    DriverManager.deregisterDriver(driver);
                } catch (SQLException e) {
                    e.printStackTrace();
                }
            }
            
            // 然后还需要停止Quartz的线程,你自己看下文档怎么停止。
        }
    2019-07-17 18:54:06
    赞同 展开评论 打赏
问答排行榜
最热
最新

相关电子书

更多
Spring Cloud Alibaba - 重新定义 Java Cloud-Native 立即下载
The Reactive Cloud Native Arch 立即下载
JAVA开发手册1.5.0 立即下载