Why does Hibernate/JDBC/MySQL drop connections after a day or so?

前端 未结 4 650
-上瘾入骨i
-上瘾入骨i 2020-12-05 08:03

I have several server processes that once in a while respond to messages from the clients and perform read-only transactions.

After about a few days that the servers

4条回答
  •  感情败类
    2020-12-05 09:04

    The MySQL JDBC driver times out after 8 hours of inactivity and drops the connection.

    You can set autoReconnect=true in your JDBC URL, and this causes the driver to reconnect if you try to query after it has disconnected. But this has side effects; for instance session state and transactions cannot be maintained over a new connection.

    If you use autoReconnect, the JDBC connection is reestablished, but it doesn't automatically re-execute your query that got the exception. So you do need to catch SQLException in your application and retry queries.

    Read http://dev.mysql.com/doc/refman/5.0/en/connector-j-reference-configuration-properties.html for more details.

提交回复
热议问题