Mysql classic "8-hour problem" and mysql Classic 8-hour Problem
Assume that your database is mysql. If the data source is improperly configured, the classic "8-hour problem" may occur ". The reason is that by default, if a connection is idle for more than 8 hours, the connection will be automatically closed on the Database End. The data source does not know that the connection has been closed. When it returns this useless connection to a dao, dao will report that the connection cannot be obtained.
If the default configuration of dbcp is used, because the default value of testOnBorrow is true, the data source checks whether the connection is correct before handing over the connection to dao, if there is a problem with the connection (the database is closed), a different connection will be taken to dao. Therefore, there will be no "8-hour problem ". If the connection validity is checked every time the connection is handed over to dao, performance problems will occur in highly concurrent applications because it requires more database access requests.
We recommend that you set testOnBorrow to false, testWhileIdle to true, and testBetweenEvictionRunsMillis (less than 8 hours ). Do not clear the connections that are closed by mysql to avoid the "eight-hour problem ".
Of course, mysql can also adjust the interactive-timeout (in seconds) configuration parameters to change the expiration time of idle connections. Therefore, when setting the timeBetweenEvictionRunsmMillis value, you must first know the maximum expiration time of the mysql idle connection.
For effective connection detection, see dbcp configuration.
The above is all the content of this article. I hope you will like it.