Network Security Internet Technology Development Database Servers Mobile Phone Android Software Apple Software Computer Software News IT Information

In addition to Weibo, there is also WeChat

Please pay attention

WeChat public account

Shulou

What if the tomcat server goes down?

2025-01-24 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Servers >

Share

Shulou(Shulou.com)06/01 Report--

This article is about tomcat server downtime to share with you what to do. Xiaobian thinks it is quite practical, so share it with everyone for reference. Let's follow Xiaobian and have a look.

Error message:

java.lang.Object.wait(Native Method)java.lang.ref.ReferenceQueue.remove(ReferenceQueue.java:143)com.mysql.jdbc.AbandonedConnectionCleanupThread.run(AbandonedConnectionCleanupThread.java:43)

Every time this error occurs, it causes tomcat application server to stop, and it never stops after adding the following java code.

Solution:

write Java code

package cn.listener;import java.sql.Driver;import java.sql.DriverManager;import java.sql.SQLException;import java.util.Enumeration;import javax.servlet.ServletContextEvent;import javax.servlet.ServletContextListener;import javax.servlet.annotation.WebListener;import com.mysql.jdbc.AbandonedConnectionCleanupThread;@WebListenerpublic class ContextFinalizer implements ServletContextListener { public void contextInitialized(ServletContextEvent sce) { } public void contextDestroyed(ServletContextEvent sce) { Enumeration 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); } } try { AbandonedConnectionCleanupThread.shutdown(); } catch (InterruptedException e) { System.out.println("ContextFinalizer:SEVERE problem cleaning up: " + e.getMessage()); e.printStackTrace(); } }}

@WebListener, this annotation is equivalent to configuring the following content in web.xml

cn.listener.ContextFinalizer

The solution can be found at the following URL:

Of course, when I refer to this solution again, I find that if the version of mysql-connection is too low, it will cause the Java code listed above to report errors. This problem can be solved by improving the version of mysql-connection.java.

Thank you for reading! About "tomcat server downtime how to do" this article is shared here, I hope the above content can have some help for everyone, so that everyone can learn more knowledge, if you think the article is good, you can share it to let more people see it!

Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.

Views: 0

*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.

Share To

Servers

Wechat

© 2024 shulou.com SLNews company. All rights reserved.

12
Report