问题
We have a problem with org.springframework.jdbc.datasource.SingleConnectionDataSource
?
We expect that the connection is never closed while the application is running, even if there is no traffic between application and db.
We configured datasource with
<property name="suppressClose" value="true"/>
what should solve the problem.
And the problem is that the connection is closed after about 30-40 minutes of inactivity (when there is no traffic between db and application).
Maybe someone with experience with SingleConnectionDataSource can help how to solve this bug or feature.
回答1:
If underneath SimpleConnectionDataSource, a MySql connection is used, then it will usually be dropped after 30-40 minutes of inactivity. Even if you use straight JDBC and create connection via:
Class.forName("com.mysql.jdbc.Driver");
Connection conn = DriverManager
.getConnection("jdbc:mysql://localhost/mydatabase?user=username&password=pass");
It will also be dropped after 30-40 mins.
来源:https://stackoverflow.com/questions/14646437/singleconnectiondatasource-connection-closed-after-about-40-minutes-inactivity