SingleConnectionDataSource connection closed after about 40 minutes inactivity

拥有回忆 提交于 2020-01-04 08:16:11

问题


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

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!