简体   繁体   English

Tomcat JDBC 连接池removeAbandoned不起作用

[英]Tomcat JDBC Connection Pool removeAbandoned not working

We have an application that's using the Tomcat JDBC Connection Pool, configured along with Spring Boot and Hibernate.我们有一个使用 Tomcat JDBC 连接池的应用程序,与 Spring 引导和 ZF8CB334B3135A2A1D7 一起配置The connection pool itself is working well (I've been able to verify that through the JMX MBean the pool provides), but a specific parameter doesn't seem to be working.连接池本身运行良好(我已经能够通过池提供的 JMX MBean 验证),但特定参数似乎不起作用。

According to the Tomcat documentation , if "removeAbandoned" is set to true a connection is considered abandoned and eligible for removal if it has been in use longer than the removeAbandonedTimeout.根据Tomcat 文档,如果“removeAbandoned”设置为 true,则如果连接的使用时间超过 removeAbandonedTimeout,则该连接被视为已放弃并有资格删除。 Thus, I've set "removeAbandoned" to true and "removeAbandonedTimeout" to 20 (seconds).因此,我将“removeAbandoned”设置为 true,将“removeAbandonedTimeout”设置为 20(秒)。 I've been able to verify that the two parameters have been properly set as well using the JMX MBean.我已经能够使用 JMX MBean 验证这两个参数是否已正确设置。

In order to test if the abandoned connections were really being removed, I locked one of my database tables manually and opened pages that accessed such a table on several browser tabs.为了测试放弃的连接是否真的被删除,我手动锁定了我的一个数据库表,并在几个浏览器选项卡上打开了访问此类表的页面。 Each one opened a new connection to my database, as I was able to verify both using the JMX MBean and using show status where `variable_name` = 'Threads_connected';每个人都打开了一个到我的数据库的新连接,因为我能够使用 JMX MBean 和使用show status where `variable_name` = 'Threads_connected'; . . However, after the 20 seconds had elapsed, none of those connections were removed.但是,在 20 秒过去后,这些连接都没有被删除。 I even waited for longer and nothing happened to them until I unlocked the table.我什至等了更长的时间,直到我打开桌子,他们什么也没发生。

From what I understood from the Tomcat documentation, those connections should all have been eligible for removal since they were both in use and lasted for more than 20 seconds.根据我从 Tomcat 文档中了解到的情况,这些连接都应该可以移除,因为它们都在使用中并且持续时间超过 20 秒。 So what's going on here?那么这里发生了什么?

My other parameters are maxActive="75", minIdle="5", maxIdle="5", initialSize="3", validationQuery="SELECT 1" and testWhileIdle="true".我的其他参数是 maxActive="75"、minIdle="5"、maxIdle="5"、initialSize="3"、validationQuery="SELECT 1" 和 testWhileIdle="true"。 I should clarify that all those connections remained active while the table was locked (none became idle again and none were removed from the pool).我应该澄清一下,当表被锁定时,所有这些连接都保持活动状态(没有一个再次空闲,也没有一个从池中删除)。

EDIT: A correction.编辑:更正。 Actually, the first connection is being removed, just not the subsequent ones.实际上,第一个连接正在被删除,而不是后续的连接。 "logAbandoned" shows all the suspect connections correctly when "suspectTimeout" is set to 20 and "removeAbandoned" is set to false.当“suspectTimeout”设置为 20 且“removeAbandoned”设置为 false 时,“logAbandoned”正确显示所有可疑连接。

Had the same problem.有同样的问题。 Please ensure you are also setting following parameters:请确保您还设置了以下参数:

  1. removeAbandoned = true removeAbandoned = true
  2. abandonWhenPercentageFull = 0 (0 is default but you can check if you are setting this value explicitly)放弃WhenPercentageFull = 0(0是默认值,但您可以检查是否明确设置此值)

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM