MySql timeouts. Should I set autoReconnect = true in a Spring application?

After periods of inactivity on my site (using Spring 2.5 and MySql), I get the following error:

org.springframework.dao.RecoverableDataAccessException: The last packet sent successfully to the server was 52,847,830 milliseconds ago. 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.

According to this question and related error , t just set autoReconnect = true. Does this mean that I have to catch this exception in any requests I make, and then retry the transaction? Should this logic be at the data access level or at the model level? Is there an easy way to handle this instead of wrapping every single request to catch it?

+3
source share
3

, . , ..

c3p0, . Spring , . - DataSource Spring.

+4

2 :

  • JDBC . Connection, Statement ResultSet finally try, . , .

  • JDBC, . , , - DB. .

+4

, ; DBCP Apache Commons.

<property name="validationQuery"> <value>SELECT 1</value>  </property>
<property name="testOnBorrow">    <value>true</value>      </property>
+3

Source: https://habr.com/ru/post/1736051/


All Articles