gpt4 book ai didi

java - Tomcat 使用 c3p0 数据源,超过 maxPoolSize

转载 作者:行者123 更新时间:2023-11-30 11:14:42 25 4
gpt4 key购买 nike

我已将 Tomcat 配置为使用 ComboPooledDataSource,方法是在我的 context.xml 中添加以下内容。

<Resource
name="jdbc/abcdatasource"
auth="Container"
type="com.mchange.v2.c3p0.ComboPooledDataSource"
factory="org.apache.naming.factory.BeanFactory"
maxPoolSize="20"
minPoolSize="5"
maxIdleTime="3000"
acquireIncrement="1"
user="abc"
password="pw_here"
driverClass="oracle.jdbc.driver.OracleDriver"
jdbcUrl="jdbc:oracle:thin:@abc.def.ghi.net:1521:BLAH"
/>

我想将数据库连接数限制为 20,如 maxPoolSize 中所定义,但我的打开连接数超过了这个数量。例如,昨天我有 35 个打开的连接。我的日志正在捕获以下内容。

2014-09-11 00:37:47,077  INFO [com.mchange.v2.async.ThreadPoolAsynchronousRunner$PoolThread-#2] NewPooledConnection:725 -  - [c3p0] Exceptions occurred while trying to close a PooledConnection's resources normally.
2014-09-11 00:37:47,077 INFO [com.mchange.v2.async.ThreadPoolAsynchronousRunner$PoolThread-#2] NewPooledConnection:735 - - [c3p0] NewPooledConnection close Exception.
java.sql.SQLException: Io exception: Connection timed out
at oracle.jdbc.driver.DatabaseError.throwSqlException(DatabaseError.java:112)
at oracle.jdbc.driver.DatabaseError.throwSqlException(DatabaseError.java:146)
at oracle.jdbc.driver.DatabaseError.throwSqlException(DatabaseError.java:255)
at oracle.jdbc.driver.T4CConnection.logoff(T4CConnection.java:481)
at oracle.jdbc.driver.PhysicalConnection.close(PhysicalConnection.java:1203)
at com.mchange.v2.c3p0.impl.NewPooledConnection.close(NewPooledConnection.java:549)
at com.mchange.v2.c3p0.impl.NewPooledConnection.close(NewPooledConnection.java:234)
at com.mchange.v2.c3p0.impl.C3P0PooledConnectionPool$1PooledConnectionResourcePoolManager.destroyResource(C3P0PooledConnectionPool.java:470)
at com.mchange.v2.resourcepool.BasicResourcePool$1DestroyResourceTask.run(BasicResourcePool.java:964)
at com.mchange.v2.async.ThreadPoolAsynchronousRunner$PoolThread.run(ThreadPoolAsynchronousRunner.java:547)
2014-09-11 00:37:47,078 WARN [com.mchange.v2.async.ThreadPoolAsynchronousRunner$PoolThread-#2] BasicResourcePool:972 - - Failed to destroy resource: com.mchange.v2.c3p0.impl.NewPooledConnection@3ca5d95d
java.sql.SQLException: Some resources failed to close properly while closing com.mchange.v2.c3p0.impl.NewPooledConnection@3ca5d95d
at com.mchange.v2.c3p0.impl.NewPooledConnection.close(NewPooledConnection.java:571)
at com.mchange.v2.c3p0.impl.NewPooledConnection.close(NewPooledConnection.java:234)
at com.mchange.v2.c3p0.impl.C3P0PooledConnectionPool$1PooledConnectionResourcePoolManager.destroyResource(C3P0PooledConnectionPool.java:470)
at com.mchange.v2.resourcepool.BasicResourcePool$1DestroyResourceTask.run(BasicResourcePool.java:964)
at com.mchange.v2.async.ThreadPoolAsynchronousRunner$PoolThread.run(ThreadPoolAsynchronousRunner.java:547)

根据这些信息,我打开的连接数超过 maxPoolSize 的可能原因是什么?

我知道有相关的stackoverflow线程,比如herehere,但不清楚我的情况可能是什么问题。在这些类似的线程中,有多个连接池——但当我将我的 Web 应用程序容器配置为使用 c3p0 ComboPooledDataSource 时,我希望有一个不同的连接池。也许我在那里遗漏了一些东西......

任何帮助将不胜感激!!!!!!

编辑 1:对于一些额外的上下文,这不是一个新的应用程序。它已经启动并运行多年。但是,新功能是将 Tomcat 与 c3p0 数据源一起使用。从 WebLogic 过渡到 Tomcat 后出现此问题。

编辑 2:当我最初创建这篇文章时,我没有提供可能非常有用的日志记录信息。 log4j 中捕获的死锁问题如下所示。自从我注意到这个问题以来,我一直在密切监视连接,并且连接增加似乎与死锁问题有关。如果非要我猜的话,我会说它在死锁之后创建了一个新的连接池。

2014-09-11 11:36:45,320  WARN [Timer-0] ThreadPoolAsynchronousRunner:608 -  - com.mchange.v2.async.ThreadPoolAsynchronousRunner$DeadlockDetector@1c203f2b -- APPARENT DEADLOCK!!! Creating emergency threads for unassigned pending tasks!
2014-09-11 11:36:45,323 WARN [Timer-0] ThreadPoolAsynchronousRunner:624 - - com.mchange.v2.async.ThreadPoolAsynchronousRunner$DeadlockDetector@1c203f2b -- APPARENT DEADLOCK!!! Complete Status:
Managed Threads: 3
Active Threads: 3
Active Tasks:
com.mchange.v2.resourcepool.BasicResourcePool$1DestroyResourceTask@4a50503d (com.mchange.v2.async.ThreadPoolAsynchronousRunner$PoolThread-#2)
com.mchange.v2.resourcepool.BasicResourcePool$1DestroyResourceTask@5ec3fae8 (com.mchange.v2.async.ThreadPoolAsynchronousRunner$PoolThread-#0)
com.mchange.v2.resourcepool.BasicResourcePool$1DestroyResourceTask@148dc5f3 (com.mchange.v2.async.ThreadPoolAsynchronousRunner$PoolThread-#1)
Pending Tasks:
com.mchange.v2.resourcepool.BasicResourcePool$1DestroyResourceTask@67bedf0f
com.mchange.v2.resourcepool.BasicResourcePool$1DestroyResourceTask@242686ff
com.mchange.v2.resourcepool.BasicResourcePool$AcquireTask@5d68e1e3
com.mchange.v2.resourcepool.BasicResourcePool$AcquireTask@10c62dfe
com.mchange.v2.resourcepool.BasicResourcePool$AcquireTask@42f5874c
com.mchange.v2.resourcepool.BasicResourcePool$AcquireTask@585b0ec
com.mchange.v2.resourcepool.BasicResourcePool$AcquireTask@c2258c9
Pool thread stack traces:
Thread[com.mchange.v2.async.ThreadPoolAsynchronousRunner$PoolThread-#2,5,main]
java.net.SocketInputStream.socketRead0(Native Method)
java.net.SocketInputStream.read(SocketInputStream.java:129)
oracle.net.ns.Packet.receive(Unknown Source)
oracle.net.ns.DataPacket.receive(Unknown Source)
oracle.net.ns.NetInputStream.getNextPacket(Unknown Source)
oracle.net.ns.NetInputStream.read(Unknown Source)
oracle.net.ns.NetInputStream.read(Unknown Source)
oracle.net.ns.NetInputStream.read(Unknown Source)
oracle.jdbc.driver.T4CMAREngine.unmarshalUB1(T4CMAREngine.java:1104)
oracle.jdbc.driver.T4CMAREngine.unmarshalSB1(T4CMAREngine.java:1075)
oracle.jdbc.driver.T4C7Ocommoncall.receive(T4C7Ocommoncall.java:106)
oracle.jdbc.driver.T4CConnection.logoff(T4CConnection.java:465)
oracle.jdbc.driver.PhysicalConnection.close(PhysicalConnection.java:1203)
com.mchange.v2.c3p0.impl.NewPooledConnection.close(NewPooledConnection.java:549)
com.mchange.v2.c3p0.impl.NewPooledConnection.close(NewPooledConnection.java:234)
com.mchange.v2.c3p0.impl.C3P0PooledConnectionPool$1PooledConnectionResourcePoolManager.destroyResource(C3P0PooledConnectionPool.java:470)
com.mchange.v2.resourcepool.BasicResourcePool$1DestroyResourceTask.run(BasicResourcePool.java:964)
com.mchange.v2.async.ThreadPoolAsynchronousRunner$PoolThread.run(ThreadPoolAsynchronousRunner.java:547)
Thread[com.mchange.v2.async.ThreadPoolAsynchronousRunner$PoolThread-#0,5,main]
java.net.SocketInputStream.socketRead0(Native Method)
java.net.SocketInputStream.read(SocketInputStream.java:129)
oracle.net.ns.Packet.receive(Unknown Source)
oracle.net.ns.DataPacket.receive(Unknown Source)
oracle.net.ns.NetInputStream.getNextPacket(Unknown Source)
oracle.net.ns.NetInputStream.read(Unknown Source)
oracle.net.ns.NetInputStream.read(Unknown Source)
oracle.net.ns.NetInputStream.read(Unknown Source)
oracle.jdbc.driver.T4CMAREngine.unmarshalUB1(T4CMAREngine.java:1104)
oracle.jdbc.driver.T4CMAREngine.unmarshalSB1(T4CMAREngine.java:1075)
oracle.jdbc.driver.T4C7Ocommoncall.receive(T4C7Ocommoncall.java:106)
oracle.jdbc.driver.T4CConnection.logoff(T4CConnection.java:465)
oracle.jdbc.driver.PhysicalConnection.close(PhysicalConnection.java:1203)
com.mchange.v2.c3p0.impl.NewPooledConnection.close(NewPooledConnection.java:549)
com.mchange.v2.c3p0.impl.NewPooledConnection.close(NewPooledConnection.java:234)
com.mchange.v2.c3p0.impl.C3P0PooledConnectionPool$1PooledConnectionResourcePoolManager.destroyResource(C3P0PooledConnectionPool.java:470)
com.mchange.v2.resourcepool.BasicResourcePool$1DestroyResourceTask.run(BasicResourcePool.java:964)
com.mchange.v2.async.ThreadPoolAsynchronousRunner$PoolThread.run(ThreadPoolAsynchronousRunner.java:547)
Thread[com.mchange.v2.async.ThreadPoolAsynchronousRunner$PoolThread-#1,5,main]
java.net.SocketInputStream.socketRead0(Native Method)
java.net.SocketInputStream.read(SocketInputStream.java:129)
oracle.net.ns.Packet.receive(Unknown Source)
oracle.net.ns.DataPacket.receive(Unknown Source)
oracle.net.ns.NetInputStream.getNextPacket(Unknown Source)
oracle.net.ns.NetInputStream.read(Unknown Source)
oracle.net.ns.NetInputStream.read(Unknown Source)
oracle.net.ns.NetInputStream.read(Unknown Source)
oracle.jdbc.driver.T4CMAREngine.unmarshalUB1(T4CMAREngine.java:1104)
oracle.jdbc.driver.T4CMAREngine.unmarshalSB1(T4CMAREngine.java:1075)
oracle.jdbc.driver.T4C7Ocommoncall.receive(T4C7Ocommoncall.java:106)
oracle.jdbc.driver.T4CConnection.logoff(T4CConnection.java:465)
oracle.jdbc.driver.PhysicalConnection.close(PhysicalConnection.java:1203)
com.mchange.v2.c3p0.impl.NewPooledConnection.close(NewPooledConnection.java:549)
com.mchange.v2.c3p0.impl.NewPooledConnection.close(NewPooledConnection.java:234)
com.mchange.v2.c3p0.impl.C3P0PooledConnectionPool$1PooledConnectionResourcePoolManager.destroyResource(C3P0PooledConnectionPool.java:470)
com.mchange.v2.resourcepool.BasicResourcePool$1DestroyResourceTask.run(BasicResourcePool.java:964)
com.mchange.v2.async.ThreadPoolAsynchronousRunner$PoolThread.run(ThreadPoolAsynchronousRunner.java:547)

正在使用的c3p0版本是0.9.1.2

最佳答案

为了它的值(value),我更新了 Tomcat 的 server.xml 并设置了 autoDeploy=false,此后我没有遇到任何问题。

我的 c3p0 连接池设置在 Tomcat 的 context.xml 中,在运行时对该文件的任何修改都会导致应用程序被重新部署并创建一个额外的连接池。将 autoDeploy 设置为 false 可防止此 Tomcat 行为产生不需要的 c3p0 连接池副作用。

关于java - Tomcat 使用 c3p0 数据源,超过 maxPoolSize,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/25811129/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com