Java – MySQL timeout – should I set autoreconnect = true in the spring application?

After a period of inactivity on my website (using spring 2.5 and MySQL), I received the following error:

org. springframework. dao. Recoverabledataaccessexception: the last packet successfully sent to the server is 52847830 milliseconds Than the 'wait' configured by the server_ 'timeout 'is the shift supervisor You should consider using pre expiration and / or testing connection validity in your application, increasing the client timeout value configured by the server, or using the connector / J connection property "autoreconnect = true" to avoid this problem

According to this question and linked bug, I shouldn't just set autoreconnect = true Does this mean that I must catch this exception in any query I make and retry the transaction? Should this logic be in the data access layer or the model layer? Is there a simple way to handle this instead of wrapping each query to capture it?

Solution

I suggest you use connection pooling They can improve performance and handle low - level details, such as reconnecting after timeout

One good is c3p0, but there are others There is support for that in spring, although I don't know all the details Here is the configuration of spring's datasource

The content of this article comes from the network collection of netizens. It is used as a learning reference. The copyright belongs to the original author.
THE END
分享
二维码
< <上一篇
下一篇>>