The mysql 8-hour solution can solve this problem in three ways: 1. Increase the value of the wait_timeout attribute of MySQL. Modify the/etc/mysql/my. cnf file at www.2cto.com and set the Java code in [mysqld ].
At the same time, only one of these two parameters works. Which parameter takes effect depends on the connection parameter specified during user connection. wait_timeout is used by default. I suggest modifying both parameters to avoid unnecessary troubles. The default values of the parameters www.2cto.com are 8 hours (60*60*8 = 28800 ). I tested changing these two parameters to 0, and the result is unexpected. The system automatically sets this value. In other words, you cannot set this value to permanent. Set these two parameters to 24 hours (60*60*24 = 604800. Set interactive_timeout = 604800; set wait_timeout = 604800; 2. Reduce the connection life cycle in the connection pool so that it is less than the value of wait_timeout set in the previous item. Modify the configuration file of c3p0 and set: # How long to keep unused connections around (in seconds) # Note: MySQL times out idle connections after 8 hours (28,800 seconds) # so ensure this value is below MySQL idle timeout cpool. maxIdleTime = 25200 in the Spring configuration file: the code is as follows: Java code <bean id = "dataSource" class = "com. mchange. v2.c3p0. comboPooledDataSource "> <property name =" maxIdleTime "value =" $ {cpool. maxIdleTime} "/> <! -- Other properties --> </bean> 3. regularly use connections in the connection pool so that they are not broken by MySQL due to idle timeout. Modify the configuration file of c3p0 and set: www.2cto.com # Prevent MySQL raise exception after a long idle timecpool. preferredTestQuery = 'select 1' cpool. idleConnectionTestPeriod = 18000cpool. testConnectionOnCheckout = true modify the Spring configuration file: the code is as follows: Java code <bean id = "dataSource" class = "com. mchange. v2.c3p0. comboPooledDataSource "> <property name =" preferredTestQuery "value =" $ {cpool. preferredTestQuery} "/> <property name =" idleConnectionTes TPeriod "value =" $ {cpool. idleConnectionTestPeriod} "/> <property name =" testConnectionOnCheckout "value =" $ {cpool. testconnectioncheckout} "/> <! -- Other properties --> </bean>