報(bào)錯(cuò)信息:
java.lang.Object.wait(Native Method)
java.lang.ref.ReferenceQueue.remove(ReferenceQueue.java:143)
com.mysql.jdbc.AbandonedConnectionCleanupThread.run(AbandonedConnectionCleanupThread.java:43)
每次出現(xiàn)這個(gè)報(bào)錯(cuò)都會(huì)導(dǎo)致tomcat應(yīng)用服務(wù)器停機(jī),加了下面的java代碼后就再也沒(méi)有停過(guò)了。
解決辦法:
編寫(xiě)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;
@WebListener
public 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,這個(gè)注解相當(dāng)于在web.xml配置如下內(nèi)容
<listener>
<listener-class>cn.listener.ContextFinalizer</listener-class>
</listener>
解決方案可以參考如下網(wǎng)址
當(dāng)然還有就是我再參考這個(gè)解決方案的時(shí)候,發(fā)現(xiàn)mysql-connection如果版本過(guò)低會(huì)導(dǎo)致上述列出的Java代碼報(bào)錯(cuò),通過(guò)提高mysql-connection.java的版本即可解決該問(wèn)題
以上就是本文的全部?jī)?nèi)容,希望對(duì)大家的學(xué)習(xí)有所幫助,也希望大家多多支持腳本之家。