报错信息:
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;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<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); } } try { AbandonedConnectionCleanupThread.shutdown(); } catch (InterruptedException e) { System.out.println("ContextFinalizer:SEVERE problem cleaning up: " + e.getMessage()); e.printStackTrace(); } }}
@WebListener,这个注解相当于在web.xml配置如下内容
<listener> <listener-class>cn.listener.ContextFinalizer</listener-class> </listener>