从 mysql-connector
切换到 mariadb
客户端库:
mysql 类 com.mysql.cj.jdbc.AbandonedConnectionCleanupThread.checkedShutdown()
的等价物是什么?
如果有的话?
(我也在使用 hikari
连接池)。
最佳答案
我不相信有等效项,看起来这个功能没有迁移到 Maria DB。更谨慎的做法是在应用程序中修复连接泄漏。
正如 HikariCP 池作者在 this message 中所解释的那样,这个强制关闭废弃连接的特性有很多问题:
Yes, we have considered it (removing abandoned connections), but ultimately we decided to pass. The problem with closing leaked connections is several fold. Some thread is possibly using that connection, and its going to blow-up (in production) somewhere if we close it. Or nothing is using that connection, and closing it has no negative impact, but now we've just covered up a leak that will cause constant cycling of connections in the pool.
Applications are responsible for cleaning up resources. Java developers tend to get lazy compared to C/C++ programmers. This is leak just like a memory leak, and both can and rightfully should eventually kill your application. How else would you 1) know a problem exist, and 2) be motivated to track it down and fix it.
We do appreciate all input, even if not adopted. In this case, users looking for a library to defensively cover-up coding errors should probably look to tomcat-jdbc.
Note, leak detection can be run in production, and can be enabled at runtime through a JMX console, so there's not a lot of justification for adding proactive connection reclamation.
关于java - mariadb 中废弃的连接清理(与 mysql 相比)?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/53187716/