NutzCN Logo
问答 Tomcat showdown 之后,无法正常关闭quartz线程,报错
发布于 2241天前 作者 qq_250553c2 3657 次浏览 复制 上一个帖子 下一个帖子
标签:

下面这个日志是,Tomcat关闭之后,报的一些异常log

25-Sep-2018 17:44:28.452 WARNING [localhost-startStop-2] org.apache.catalina.loader.WebappClassLoaderBase.clearReferencesJdbc The web application [Backend] registered the JDBC driver [com.alibaba.druid.proxy.DruidDriver] but failed to unregister it when the web application was stopped. To prevent a memory leak, the JDBC Driver has been forcibly unregistered.
25-Sep-2018 17:44:28.453 WARNING [localhost-startStop-2] org.apache.catalina.loader.WebappClassLoaderBase.clearReferencesJdbc The web application [Backend] registered the JDBC 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.
25-Sep-2018 17:44:28.453 WARNING [localhost-startStop-2] org.apache.catalina.loader.WebappClassLoaderBase.clearReferencesThreads The web application [Backend] appears to have started a thread named [Abandoned connection cleanup thread] but has failed to stop it. This is very likely to create a memory leak. Stack trace of thread:
 java.lang.Object.wait(Native Method)
 java.lang.ref.ReferenceQueue.remove(ReferenceQueue.java:143)
 com.mysql.jdbc.AbandonedConnectionCleanupThread.run(AbandonedConnectionCleanupThread.java:43)
25-Sep-2018 17:44:28.456 WARNING [localhost-startStop-2] org.apache.catalina.loader.WebappClassLoaderBase.clearReferencesThreads The web application [Backend] appears to have started a thread named [DefaultQuartzScheduler_Worker-1] but has failed to stop it. This is very likely to create a memory leak. Stack trace of thread:
 java.lang.Object.wait(Native Method)
 org.quartz.simpl.SimpleThreadPool$WorkerThread.run(SimpleThreadPool.java:568)
25-Sep-2018 17:44:28.457 WARNING [localhost-startStop-2] org.apache.catalina.loader.WebappClassLoaderBase.clearReferencesThreads The web application [Backend] appears to have started a thread named [DefaultQuartzScheduler_Worker-2] but has failed to stop it. This is very likely to create a memory leak. Stack trace of thread:
 java.lang.Object.wait(Native Method)
 org.quartz.simpl.SimpleThreadPool$WorkerThread.run(SimpleThreadPool.java:568)
25-Sep-2018 17:44:28.457 WARNING [localhost-startStop-2] org.apache.catalina.loader.WebappClassLoaderBase.clearReferencesThreads The web application [Backend] appears to have started a thread named [DefaultQuartzScheduler_Worker-3] but has failed to stop it. This is very likely to create a memory leak. Stack trace of thread:
 java.lang.Object.wait(Native Method)
 org.quartz.simpl.SimpleThreadPool$WorkerThread.run(SimpleThreadPool.java:568)
25-Sep-2018 17:44:28.457 WARNING [localhost-startStop-2] org.apache.catalina.loader.WebappClassLoaderBase.clearReferencesThreads The web application [Backend] appears to have started a thread named [DefaultQuartzScheduler_Worker-4] but has failed to stop it. This is very likely to create a memory leak. Stack trace of thread:
 java.lang.Object.wait(Native Method)
 org.quartz.simpl.SimpleThreadPool$WorkerThread.run(SimpleThreadPool.java:568)
25-Sep-2018 17:44:28.458 WARNING [localhost-startStop-2] org.apache.catalina.loader.WebappClassLoaderBase.clearReferencesThreads The web application [Backend] appears to have started a thread named [DefaultQuartzScheduler_Worker-5] but has failed to stop it. This is very likely to create a memory leak. Stack trace of thread:
 java.lang.Object.wait(Native Method)
 org.quartz.simpl.SimpleThreadPool$WorkerThread.run(SimpleThreadPool.java:568)
25-Sep-2018 17:44:28.458 WARNING [localhost-startStop-2] org.apache.catalina.loader.WebappClassLoaderBase.clearReferencesThreads The web application [Backend] appears to have started a thread named [DefaultQuartzScheduler_Worker-6] but has failed to stop it. This is very likely to create a memory leak. Stack trace of thread:
 java.lang.Object.wait(Native Method)
 org.quartz.simpl.SimpleThreadPool$WorkerThread.run(SimpleThreadPool.java:568)
25-Sep-2018 17:44:28.458 WARNING [localhost-startStop-2] org.apache.catalina.loader.WebappClassLoaderBase.clearReferencesThreads The web application [Backend] appears to have started a thread named [DefaultQuartzScheduler_Worker-7] but has failed to stop it. This is very likely to create a memory leak. Stack trace of thread:
 java.lang.Object.wait(Native Method)
 org.quartz.simpl.SimpleThreadPool$WorkerThread.run(SimpleThreadPool.java:568)
25-Sep-2018 17:44:28.459 WARNING [localhost-startStop-2] org.apache.catalina.loader.WebappClassLoaderBase.clearReferencesThreads The web application [Backend] appears to have started a thread named [DefaultQuartzScheduler_Worker-8] but has failed to stop it. This is very likely to create a memory leak. Stack trace of thread:
 java.net.PlainSocketImpl.socketConnect(Native Method)
 java.net.AbstractPlainSocketImpl.doConnect(AbstractPlainSocketImpl.java:350)
 java.net.AbstractPlainSocketImpl.connectToAddress(AbstractPlainSocketImpl.java:206)
 java.net.AbstractPlainSocketImpl.connect(AbstractPlainSocketImpl.java:188)
 java.net.SocksSocketImpl.connect(SocksSocketImpl.java:392)
 java.net.Socket.connect(Socket.java:589)
 com.mysql.jdbc.StandardSocketFactory.connect(StandardSocketFactory.java:213)
 com.mysql.jdbc.MysqlIO.<init>(MysqlIO.java:297)
 com.mysql.jdbc.ConnectionImpl.coreConnect(ConnectionImpl.java:2232)
 com.mysql.jdbc.ConnectionImpl.connectOneTryOnly(ConnectionImpl.java:2265)
 com.mysql.jdbc.ConnectionImpl.createNewIO(ConnectionImpl.java:2064)
 com.mysql.jdbc.ConnectionImpl.<init>(ConnectionImpl.java:790)
 com.mysql.jdbc.JDBC4Connection.<init>(JDBC4Connection.java:44)
 sun.reflect.GeneratedConstructorAccessor35.newInstance(Unknown Source)
 sun.reflect.DelegatingConstructorAccessorImpl.newInstance(DelegatingConstructorAccessorImpl.java:45)
 java.lang.reflect.Constructor.newInstance(Constructor.java:423)
 com.mysql.jdbc.Util.handleNewInstance(Util.java:377)
 com.mysql.jdbc.ConnectionImpl.getInstance(ConnectionImpl.java:395)
 com.mysql.jdbc.NonRegisteringDriver.connect(NonRegisteringDriver.java:325)
 java.sql.DriverManager.getConnection(DriverManager.java:664)
 java.sql.DriverManager.getConnection(DriverManager.java:247)
 org.nutz.dao.impl.SimpleDataSource.getConnection(SimpleDataSource.java:42)
 org.nutz.trans.Trans.getConnectionAuto(Trans.java:263)
 org.nutz.dao.jdbc.Jdbcs.getExpert(Jdbcs.java:106)
 org.nutz.dao.impl.DaoSupport.setDataSource(DaoSupport.java:187)
 org.nutz.dao.impl.DaoSupport.setDataSource(DaoSupport.java:178)
 org.nutz.dao.impl.NutDao.<init>(NutDao.java:104)
 com.backend.utils.DbConfigUtil.getNutDao(DbConfigUtil.java:61)
 com.backend.timer.OnlinePlayerJob.execute(OnlinePlayerJob.java:56)
 org.quartz.core.JobRunShell.run(JobRunShell.java:202)
 org.quartz.simpl.SimpleThreadPool$WorkerThread.run(SimpleThreadPool.java:573)
25-Sep-2018 17:44:28.459 WARNING [localhost-startStop-2] org.apache.catalina.loader.WebappClassLoaderBase.clearReferencesThreads The web application [Backend] appears to have started a thread named [DefaultQuartzScheduler_Worker-9] but has failed to stop it. This is very likely to create a memory leak. Stack trace of thread:
 java.lang.Object.wait(Native Method)
 org.quartz.simpl.SimpleThreadPool$WorkerThread.run(SimpleThreadPool.java:568)
25-Sep-2018 17:44:28.459 WARNING [localhost-startStop-2] org.apache.catalina.loader.WebappClassLoaderBase.clearReferencesThreads The web application [Backend] appears to have started a thread named [DefaultQuartzScheduler_Worker-10] but has failed to stop it. This is very likely to create a memory leak. Stack trace of thread:
 java.lang.Object.wait(Native Method)
 org.quartz.simpl.SimpleThreadPool$WorkerThread.run(SimpleThreadPool.java:568)

下面是我在初始化的时候处理的quartz的corn

public class MainSetup implements Setup {

    private static final Logger log = Logger.getLogger(MainSetup.class);

    @Override
    public void destroy(NutConfig conf) {
        ThreadPoolManager.getInstance().destroy();
    }

    @Override
    public void init(NutConfig conf) {
        log.info("MainSetup init ----------------------");
        Ioc ioc = conf.getIoc();
        Dao backendDao = ioc.get(Dao.class, "backendDao");//后台数据库连接

        log.info("后台数据库连接 配置读取 backendDao:" + backendDao);

        Dao publicServerDao = ioc.get(Dao.class, "daoPublic");//公共数据库
        ioc.get(NutQuartzCronJobFactory.class);

        Daos.createTablesInPackage(backendDao, "com.backend", false);

这个在入口方法处理的quartzloader

@SetupBy(MainSetup.class)
@Modules(scanPackage=true)
@IocBy(type=ComboIocProvider.class, args={
    "*js", "ioc/",
    "*anno", "com.backend",
    "*tx",
    "*org.nutz.integration.quartz.QuartzIocLoader"})
@Fail("jsp:jsp.500")
@Localization(value="language/", defaultLocalizationKey="zh_CN")
@Filters(@By(type = CheckSession.class,args={"USER","/user/tologin"}))
public class MainModule {}
8 回复

有没有自行添加quartz.js?

下面是自己填的quartz.js

var ioc = {
   "scheduler" :{
      "type" :"org.quartz.Scheduler",
      "factory" :"org.quartz.impl.StdSchedulerFactory#getDefaultScheduler",
      "events" :{
         "create" :"start",
         "depose" :"shutdown"
      },
      "fields" :{
         "jobFactory" :{
            "refer" :"jobFactory"
         }
      }
   },
   "jobFactory" :{
      "type" :"org.nutz.integration.quartz.NutQuartzJobFactory",
      "args" :[{
         "refer" :"$ioc"
      }]
   },
   "nutQuartzCronJobFactory" :{
      "type" :"org.nutz.integration.quartz.NutQuartzCronJobFactory",
      "events" :{
         "create" :"init"
      },
      "fields" :{
         "scheduler" :{
            "refer" :"scheduler"
         },
         "conf" :{
            "refer" :"conf"
         }
      }
   } 
};

一般来说不需要自行添加

不过里面已经有 "depose" :"shutdown", 理应关闭quartz了

 org.nutz.dao.impl.NutDao.<init>(NutDao.java:104)
 com.backend.utils.DbConfigUtil.getNutDao(DbConfigUtil.java:61)
 com.backend.timer.OnlinePlayerJob.execute(OnlinePlayerJob.java:56)
 org.quartz.core.JobRunShell.run(JobRunShell.java:202)
 org.quartz.simpl.SimpleThreadPool$WorkerThread.run(SimpleThreadPool.java:573)

你这个JobRunShell是一直阻塞的?

我的理解应该没有阻塞吧?由于quartz并没有因为Tomcat关闭而关闭,到时任务触发的时候再次启动,然后数据库又在Tomcat关闭的时候关闭了,而无法正常再次链接,所以报了这个异常,不知道这个理解是不是对的。

已经调用过shutdown的

还可以在depose的时候

conf.getIoc().get(Scheduler.class).shutdown(true);

但看这日志,像是卡在JobRunShell里面

好的,我试试,谢谢老师

添加回复
请先登陆
回到顶部