tomcat - Tomcat 忽略 removeAbandonedTimeout 并关闭池中的连接
问题描述
我正在使用 commons dbcp 在 as400 上使用 JDBC 连接到 DB2 的 tomcat 7.0 上工作。一旦我在服务器上加载负载,它就会立即打开和关闭与数据库的连接,而忽略我设置的 30 分钟 removeAbandonedTimeout 设置。我尝试了几种设置都无济于事。例如,在 15 秒的时间间隔内,它将无缘无故地打开 150 个连接并关闭 140 个连接。我们让这个应用程序在旧的 WebSphere 服务器上运行,它不会关闭连接,除非它们真的空闲。
这是我的配置:
<Resource name="MYDB"
auth="Container"
type="javax.sql.DataSource"
factory="org.apache.tomcat.dbcp.dbcp.BasicDataSourceFactory"
driverClassName="com.ibm.as400.access.AS400JDBCDriver"
url="jdbc:as400://mydb.na.sysco.net;blockCriteria=2;dateFormat=iso;libraries=*LIBL;naming=system;errors=full"
username="user"
password="pass"
maxActive="350"
maxWait="180000"
minIdle="10"
maxIdle="50"
testWhileIdle="true"
validationQuery="select 1 from sysibm.sysdummy1"
timeBetweenEvictionRunsMillis="34000"
minEvictableIdleTimeMillis="1800000"
removeAbandonedTimeout="1800"
removeAbandoned="true"
logAbandoned="true"/>
当系统空闲或只有几个测试帐户时,它会按预期运行,但是一旦我在服务器上加载,大量打开和关闭立即开始。例如,它将在相同的 15 秒间隔内打开 150 个连接并关闭 90 个连接。我正在从我的监控软件读取与 as400 上 QZ 作业的开始和结束相关的套接字打开和关闭。在使用连接时,它将不断执行此操作。
这违背了连接池的目的。任何想法或想法表示赞赏。
也令人困惑,因为不清楚我应该从哪些参数开始。不接受与Tomcat JDBC 连接池参数不同的commons dbcp 参数,即removeAbandonedOnMaintenance。但是 minEvictableIdleTimeMillis 的默认值 1800000 是从 Tomcat jdbc 池参数中获取的,而不是 60000。
https://commons.apache.org/proper/commons-dbcp/api-1.2.2/index.html
https://tomcat.apache.org/tomcat-7.0-doc/jdbc-pool.html
当我没有明确设置参数时,这就是我得到的默认值。它似乎列出了所有 tomcat jdbc 池参数,而不是 commons DBCP 参数。但是,它从 commons DBCP 中选择 minEvictableIdleTimeout 的默认值,而不是从 Tomcat JDBC 连接池参数中选择 60 秒。奇怪的部分是removeAbandoned 参数没有为commons dbcp 列出,它是removeAbandonedOnMaintenance 和removeAbandonedOnBorrow。一个星期以来,我一直试图把这种果冻钉在墙上。
我使用 jmxproxy 来获取实时统计信息和设置。
http://myserver:8080/manager/jmxproxy/?qry=Catalina%3Atype%3DDataSource%2C *
Name: Catalina:type=DataSource,class=javax.sql.DataSource,name="EOPDB"
modelerType: org.apache.tomcat.util.modeler.BaseModelMBean
maxIdle: 8
testOnBorrow: false
defaultTransactionIsolation: -1
testOnReturn: false
maxActive: 350
numActive: 104
numTestsPerEvictionRun: 3
minIdle: 0
maxWait: 180000
closed: false
defaultAutoCommit: true
numIdle: 8
validationQueryTimeout: -1
testWhileIdle: false
driverClassName: com.ibm.as400.access.AS400JDBCDriver
accessToUnderlyingConnectionAllowed: false
url: jdbc:as400://mydb;blockCriteria=2;dateFormat=iso;libraries=*LIBL;naming=system;errors=full
removeAbandonedTimeout: 300
defaultReadOnly: false
logAbandoned: false
poolPreparedStatements: false
maxOpenPreparedStatements: -1
removeAbandoned: false
minEvictableIdleTimeMillis: 1800000
timeBetweenEvictionRunsMillis: -1
initialSize: 0
解决方案
maxIdle 是池中可以保持空闲的最大连接数。一旦空闲连接数超过 maxIdle,应用程序释放的任何连接都会立即关闭,而不会根据 minEvictableIdleTimeMillis 检查连接空闲时间。
推荐阅读
- c# - 如何反序列化动态 JsonProperty?
- protractor - 获取错误 protractor_1.browser.action 不是函数
- excel - 使用 Haskell 将 .xls 或 .xlsx 转换为 CSV 文件
- parquet - 如何在 Parquet 文件中增量存储时间序列以进行有效检索?
- php - 未找到基表或视图?
- html - HTML 字段集:表单属性不起作用
- javascript - 在纯节点 js 中将 mp4 或 Avi 转换为 m3u8
- python - 处理 pdf 中的图像信息和路径
- linux - 使用 FTP 下载特定文件名
- abaqus - Abaqus,边界条件如何影响规定的材料响应?