本文介绍了即使使用'autoReconnect = true',MySql JDBC超时的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

有时,我的Java/Tomcat6/Debian Squeeze应用程序无法与MySql服务器通信.Tomcat应用程序位于前端服务器上,而MySql位于单独的仅MySql的框中.一个典型的错误是:

Occasionally, my Java/Tomcat6/Debian Squeeze application can't talk to the MySql server.The Tomcat application is on a front-end server and MySql is on a separate, MySql-only box. A typical error is:

com.mysql.jdbc.exceptions.jdbc4.CommunicationsException: The last packet successfully received from the server was56588 milliseconds ago.

The last packet sent successfully to the server was 56588 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.

给出的超时时间仅为60秒,这似乎很短.如果是一个小时或更长时间,我将简单地设置一个后台任务,每隔几分钟对db服务器执行一次ping操作.我已将autoReconnect参数添加到开头的URL中,没有明显的影响.

The timeout time given is only 60 seconds, which seems very short. If it was an hour or more, I would simply setup a background task to ping the DB-server every few minutes. I've added the autoReconnect parameter to the opening URL, with no obvious impact.

关于这里的问题有什么想法吗?谢谢帕特

Any idea as to what the problem is here?ThanksPat

推荐答案

配置c3p0属性以解决此问题.使用类似的属性,

Configure c3p0 properties for overcome this issue. Use properties like,

hibernate.connection.provider_class=org.hibernate.connection.C3P0ConnectionProvider
hibernate.c3p0.min_size=0
hibernate.c3p0.max_size=20
hibernate.c3p0.timeout=500
hibernate.c3p0.max_statements=50
hibernate.c3p0.idle_test_period=3000
hibernate.c3p0.testConnectionOnCheckout=true
hibernate.c3p0.acquire_increment=1

具有JDBC连接URL url=jdbc:mysql://host/databasename?autoReconnect=true

with JDBC connection URL url=jdbc:mysql://host/databasename?autoReconnect=true

这篇关于即使使用'autoReconnect = true',MySql JDBC超时的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

11-01 19:22