MySql JDBC timeout even with 'autoReconnect=true' [duplicate]

若如初见. 提交于 2019-12-23 09:18:18

问题


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.

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? Thanks Pat


回答1:


You should code for network glitches and deal with auto-reconnect yourself.

auto-reconnect is deliberately OFF because of several 'application' bugs that can silently happen when the connection goes away and comes back in a different state.

Anyway, a comment shows that this is somewhat a Duplicate question.




回答2:


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

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



来源:https://stackoverflow.com/questions/9674165/mysql-jdbc-timeout-even-with-autoreconnect-true

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!