加入收藏 | 设为首页 | 会员中心 | 我要投稿 李大同 (https://www.lidatong.com.cn/)- 科技、建站、经验、云计算、5G、大数据,站长网!
当前位置: 首页 > 编程开发 > Java > 正文

tomcat服务器宕机解决方案

发布时间:2020-12-15 07:15:31 所属栏目:Java 来源:网络整理
导读:报错信息: ?java.lang.Object.wait(Native Method) ?java.lang.ref.ReferenceQueue.remove(ReferenceQueue.java:143) ?com.mysql.jdbc.AbandonedConnectionCleanupThread.run(AbandonedConnectionCleanupThread.java:43) 每次出现这个报错都会导致tomcat应用

报错信息:

?java.lang.Object.wait(Native Method)

?java.lang.ref.ReferenceQueue.remove(ReferenceQueue.java:143)

?com.mysql.jdbc.AbandonedConnectionCleanupThread.run(AbandonedConnectionCleanupThread.java:43)

每次出现这个报错都会导致tomcat应用服务器停机,加了下面的java代码后就再也没有停过了。

解决办法:

编写Java代码

package cn.listener;

import java.sql.Driver;
 java.sql.DriverManager;
 java.sql.SQLException;
 java.util.Enumeration;

 javax.servlet.ServletContextEvent;
 javax.servlet.ServletContextListener;
 javax.servlet.annotation.WebListener;

 com.mysql.jdbc.AbandonedConnectionCleanupThread;


@WebListener
public class ContextFinalizer implements ServletContextListener {

    void contextInitialized(ServletContextEvent sce) {
    }

     contextDestroyed(ServletContextEvent sce) {
        Enumeration<Driver> drivers = DriverManager.getDrivers();
        Driver d = null;
        while (drivers.hasMoreElements()) {
            try {
                d = drivers.nextElement();
                DriverManager.deregisterDriver(d);
                System.out.println(String.format("ContextFinalizer:Driver %s deregistered",d));
            } catch (SQLException ex) {
                System.out.println(String.format("ContextFinalizer:Error deregistering driver %s",d) + ":" + ex);
            }
        }
         {
            AbandonedConnectionCleanupThread.shutdown();
        }  (InterruptedException e) {
            System.out.println("ContextFinalizer:SEVERE problem cleaning up: " + e.getMessage());
            e.printStackTrace();
        }
    }
}

?

@WebListener,这个注解相当于在web.xml配置如下内容
  <listener>
    listener-class>cn.listener.ContextFinalizer</>
  >

?

?

解决方案可以参考如下网址:https://stackoverflow.com/questions/25699985/the-web-application-appears-to-have-started-a-thread-named-abandoned-connect

?

当然还有就是我再参考这个解决方案的时候,发现mysql-connection如果版本过低会导致上述列出的Java代码报错,通过提高mysql-connection.java的版本即可解决该问题

?

(编辑:李大同)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!

    推荐文章
      热点阅读