"连接超时" Tomcat& Mysql的

时间:2015-07-30 06:25:29

标签: mysql tomcat socketexception

问题 Tomcat向Mysql发送请求时发生Socket异常。

一整天都会发生10次左右。由于它很少发生,这似乎是一个角落问题。关于如何进一步调试/修复它的任何输入?

设置详情 Linux上的Tomcat; MySQL的

堆栈跟踪

java.sql.SQLException: Communication link failure: java.net.SocketException, underlying cause: Connection timed out

开始嵌入异常

java.net.SocketException

消息:连接超时

堆栈跟踪:

java.net.SocketException: Connection timed out

at java.net.SocketInputStream.socketRead0(Native Method)

at java.net.SocketInputStream.read(SocketInputStream.java:146)

at com.mysql.jdbc.MysqlIO.readFully(MysqlIO.java:1392)

at com.mysql.jdbc.MysqlIO.reuseAndReadPacket(MysqlIO.java:1539)

at com.mysql.jdbc.MysqlIO.checkErrorPacket(MysqlIO.java:1930)

at com.mysql.jdbc.MysqlIO.sendCommand(MysqlIO.java:1168)

at com.mysql.jdbc.MysqlIO.sqlQueryDirect(MysqlIO.java:1279)

at com.mysql.jdbc.MysqlIO.sqlQuery(MysqlIO.java:1225)

at com.mysql.jdbc.Connection.execSQL(Connection.java:2278)

at com.mysql.jdbc.Connection.execSQL(Connection.java:2225)

at com.mysql.jdbc.Statement.executeQuery(Statement.java:1163)

at sun.reflect.GeneratedMethodAccessor47.invoke(Unknown Source)

at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)

at java.lang.reflect.Method.invoke(Method.java:622)

at org.apache.tomcat.jdbc.pool.interceptor.AbstractQueryReport$StatementProxy.invoke(AbstractQueryReport.ja

va:235)

at com.sun.proxy.$Proxy16.executeQuery(Unknown Source)

at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1146)

at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:615)

at java.lang.Thread.run(Thread.java:701)

END NESTED EXCEPTION

at com.mysql.jdbc.MysqlIO.reuseAndReadPacket(MysqlIO.java:1714)

at com.mysql.jdbc.MysqlIO.checkErrorPacket(MysqlIO.java:1930)

at com.mysql.jdbc.MysqlIO.sendCommand(MysqlIO.java:1168)

at com.mysql.jdbc.MysqlIO.sqlQueryDirect(MysqlIO.java:1279)

at com.mysql.jdbc.MysqlIO.sqlQuery(MysqlIO.java:1225)

at com.mysql.jdbc.Connection.execSQL(Connection.java:2278)

at com.mysql.jdbc.Connection.execSQL(Connection.java:2225)

at com.mysql.jdbc.Statement.executeQuery(Statement.java:1163)

at sun.reflect.GeneratedMethodAccessor47.invoke(Unknown Source)

at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)

at java.lang.reflect.Method.invoke(Method.java:622)

at org.apache.tomcat.jdbc.pool.interceptor.AbstractQueryReport$StatementProxy.invoke(AbstractQueryReport.ja

va:235)

at com.sun.proxy.$Proxy16.executeQuery(Unknown Source)

at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1146)

at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:615)

at java.lang.Thread.run(Thread.java:701)

2 个答案:

答案 0 :(得分:0)

请确保您的应用程序在使用后关闭连接。如果您没有关闭连接,那么在一段时间后它将达到最大连接数。之后你就无法创建连接。只有在达到超时后,mysql才会关闭该连接(实际应该关闭)。之后,您可以使用该连接。所以请检查您的连接关闭代码。

答案 1 :(得分:0)

异常 java.net.SocketException:连接超时可能是由于很多原因。

但是既然你提到你在白天只面对它几次并且它正常工作,我认为检查以下两点之一可能会有所帮助。

  1. 检查mysql的 wait_timeout 属性。查看this link

  2. 检查mysql的 max_connections 属性。查看this link