jdbc4 通信异常
我有一台运行 java 应用程序的机器,与在同一实例上运行的 mysql 实例通信。 该应用程序 使用 mysql 的 jdbc4 驱动程序。 我不断收到 com.mysql.jdbc.exceptions.jdbc4.CommunicationsException 在随机时间。
这是整个消息。
无法打开事务的 JDBC 连接; 嵌套异常
com.mysql.jdbc.exceptions.jdbc4.CommunicationsException: The last packet successfully received from the server was25899 milliseconds ago.The last packet sent successfully to the server was 25899 milliseconds ago, which is longer than the server configured value of 'wait_timeout'. You should consider either expiring and/or testing connection validity before use in your application, increasing the server configured values for client timeouts, or using the Connector/J connection property 'autoReconnect=true' to avoid this problem.
对于 mysql,全局“wait_timeout”和“interactive_timeout”的值设置为 3600 秒,“connect_timeout”设置为 60 秒。 等待超时值远高于 26 秒(25899 毫秒)。 异常跟踪中提到。
我使用 dbcp 进行连接池,这里是数据源的 spring bean 配置。
<bean id="dataSource" destroy-method="close" class="org.apache.commons.dbcp.BasicDataSource" >
<property name="driverClassName" value="com.mysql.jdbc.Driver"/>
<property name="url" value="jdbc:mysql://localhost:3306/db"/>
<property name="username" value="xxx"/>
<property name="password" value="xxx" />
<property name="poolPreparedStatements" value="false" />
<property name="maxActive" value="3" />
<property name="maxIdle" value="3" />
</bean>
知道为什么会发生这种情况吗? 使用c3p0可以解决问题吗?
I have a machine running a java app talking to a mysql instance running on the same instance. the app
uses jdbc4 drivers from mysql. I keep getting com.mysql.jdbc.exceptions.jdbc4.CommunicationsException
at random times.
Here is the whole message.
Could not open JDBC Connection for transaction; nested exception is
com.mysql.jdbc.exceptions.jdbc4.CommunicationsException: The last packet successfully received from the server was25899 milliseconds ago.The last packet sent successfully to the server was 25899 milliseconds ago, which is longer than the server configured value of 'wait_timeout'. You should consider either expiring and/or testing connection validity before use in your application, increasing the server configured values for client timeouts, or using the Connector/J connection property 'autoReconnect=true' to avoid this problem.
For mysql, the value of global 'wait_timeout' and 'interactive_timeout' is set to 3600 seconds and 'connect_timeout' is set to 60 secs. the wait timeout value is much higher than the 26 secs(25899 msecs). mentioned in the exception trace.
I use dbcp for connection pooling and here is spring bean config for the datasource.
<bean id="dataSource" destroy-method="close" class="org.apache.commons.dbcp.BasicDataSource" >
<property name="driverClassName" value="com.mysql.jdbc.Driver"/>
<property name="url" value="jdbc:mysql://localhost:3306/db"/>
<property name="username" value="xxx"/>
<property name="password" value="xxx" />
<property name="poolPreparedStatements" value="false" />
<property name="maxActive" value="3" />
<property name="maxIdle" value="3" />
</bean>
Any idea why this could be happening? Will using c3p0 solve the problem ?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(4)
尝试正确设置 Apache Commons DBCP。
您需要设置:
这应该可以解决问题。
Try setting up the Apache Commons DBCP correctly.
You need to set:
That should fix the problem.
您能描述一下您的应用程序如何处理连接池吗? 我怀疑 JDBC 驱动程序中的 autoReconnect=true 会重新池化来自您应用程序的连接。 应用程序在失去连接时需要重新连接。
Can you describe how your app is handling connection pooling? I doubt that autoReconnect=true in the JDBC driver would re-pool connections from your app. The app needs to reconnect when it loses a connection.
我会遵循例外情况中的建议。 您应该考虑:
我怀疑 C3P0 是否会比您已经使用的 DBCP 好得多。 例外的是给你一些具体的建议。 你已经尝试过#3。 另外两个呢?
我知道如何要求 WebLogic 在使用连接之前检查连接。 您应该了解如何对 Tomcat 执行相同的操作。
I'd follow the advice in the exception. You should consider either:
I doubt that C3P0 will be that much better than the DBCP that you're already using. The exception is giving you some specific advice. You've tried #3. What about the other two?
I know how to ask WebLogic to check connections before using them. You should find out how to do the same with Tomcat.
我以前见过在网络上移动的 Windows 计算机在连接到自身时遇到问题。
JVM 之外是否存在任何连接问题 - 即 mysql 客户端连接到服务器、超时等?
I have seen before that Windows machines which have been moved on the network have had trouble with connecting to themselves.
Is there any connectivity problems outside the JVM - i.e. mysql client connecting to the server, and timing out, etc?