Get the App
SLTechnology News&Howtos  ›  Servers  › 

What if the tomcat server goes down?

Shulou Source: shulou.com Published: 2022-06-01 16:10:45 09月17日 Update

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!

Tags: Server service code content reference what to do scheme more version article solution good practical information method that is article time comment see Apple Docker Huawei Linux macOS MariaDB Microsoft MySQL NVidia OPPO Reno Microsoft Shulou Information macOS Shulou Technology Apple