2014-09-12 101 views
2

我已经配置Tomcat使用ComboPooledDataSource,通过在我的context.xml中添加以下内容。Tomcat使用c3p0数据源,maxPoolSize超过

<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: [email protected] 
java.sql.SQLException: Some resources failed to close properly while closing [email protected] 
     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中捕获的DEADLOCK问题如下所示。自从我注意到这个问题以来,我一直在密切关注连接,并且连接增加似乎与死锁问题有关。如果我不得不猜测,我会说它是在死锁之后创建一个新的连接池。

2014-09-11 11:36:45,320 WARN [Timer-0] ThreadPoolAsynchronousRunner:608 - - com[email protected]1c203f2b -- APPARENT DEADLOCK!!! Creating emergency threads for unassigned pending tasks! 
2014-09-11 11:36:45,323 WARN [Timer-0] ThreadPoolAsynchronousRunner:624 - - com[email protected]1c203f2b -- APPARENT DEADLOCK!!! Complete Status: 
     Managed Threads: 3 
     Active Threads: 3 
     Active Tasks: 
       com[email protected]4a50503d (com.mchange.v2.async.ThreadPoolAsynchronousRunner$PoolThread-#2) 
       com[email protected]5ec3fae8 (com.mchange.v2.async.ThreadPoolAsynchronousRunner$PoolThread-#0) 
       com[email protected]148dc5f3 (com.mchange.v2.async.ThreadPoolAsynchronousRunner$PoolThread-#1) 
     Pending Tasks: 
       com[email protected]67bedf0f 
       com[email protected]242686ff 
       [email protected]e3 
       [email protected]fe 
       [email protected]4c 
       [email protected]c 
       [email protected]9 
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

+0

几个问题:你如何测量打开的连接(在数据库中或只是在Java代码中打印连接对象)?你如何从代码获取连接? getConnection()或getConnection(用户名,密码)? 从您的异常追踪中,看起来连接没有关闭。你能从数据库角度找出原因吗? – prabugp 2014-09-12 14:58:40

+1

主要从服务器上运行tomcat我使用命令测量打开的连接#netstat -an | grep 1521.我们的DBA也仅从数据库的角度检查了开放连接,这与我所看到的一致。 – 2014-09-12 15:10:11

+0

关于获取连接的方法,这是我可以挖掘的,但我的印象是,即使使用getConnection(username,password)方法,它也不会创建多个连接池,因为我有在context.xml中正好配置了一个用户名和密码。 – 2014-09-12 15:12:23

回答

1

对于它的价值,我更新的Tomcat的server.xml并设置自动部署=假,因为我还没有遇到任何问题。

我的c3p0连接池设置位于Tomcat的context.xml中,并且在运行时对该文件的任何修改都会导致重新部署应用程序并创建附加连接池。将autoDeploy设置为false可防止具有不需要的c3p0连接池副作用的Tomcat行为。

相关问题