You are viewing a plain text version of this content. The canonical link for it is here.
Posted to issues@commons.apache.org by "Adrian Woodhead (JIRA)" <ji...@apache.org> on 2008/07/09 19:47:32 UTC

[jira] Commented: (DBCP-272) Contention for DriverManager when initializing multiple datasources

    [ https://issues.apache.org/jira/browse/DBCP-272?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=12612202#action_12612202 ] 

Adrian Woodhead commented on DBCP-272:
--------------------------------------

Interestingly, we tried to replace the DBCP connection pool with c3p0. We did not mark the datasources as lazy-init in spring. c3p0 exhibited very similar behaviour to dbcp, what is does better is that it actually detects the deadlock itself and outputs some useful information related to this It seems it also blocks in DirverManager.registerDriver and in doing the Class.forName step:

[2008-07-09 17:31:24] WARN (com.mchange.v2.async.ThreadPoolAsynchronousRunner:608) - com.mchange.v2.async.ThreadPoolAsynchronousRunner$DeadlockDetector@2cec4462 -- APPARENT DEADLOCK!!! Creating emergency threads for unassigned pending tasks!
[2008-07-09 17:31:24] WARN (com.mchange.v2.async.ThreadPoolAsynchronousRunner:624) - com.mchange.v2.async.ThreadPoolAsynchronousRunner$DeadlockDetector@2cec4462 -- APPARENT DEADLOCK!!! Complete Status: 
	Managed Threads: 3
	Active Threads: 3
	Active Tasks: 
		com.mchange.v2.resourcepool.BasicResourcePool$AcquireTask@21bf4c80 (com.mchange.v2.async.ThreadPoolAsynchronousRunner$PoolThread-#0)
		com.mchange.v2.resourcepool.BasicResourcePool$AcquireTask@163778cf (com.mchange.v2.async.ThreadPoolAsynchronousRunner$PoolThread-#1)
		com.mchange.v2.resourcepool.BasicResourcePool$AcquireTask@13dc696e (com.mchange.v2.async.ThreadPoolAsynchronousRunner$PoolThread-#2)
	Pending Tasks: 
		com.mchange.v2.resourcepool.BasicResourcePool$AcquireTask@6b8dbef1
		com.mchange.v2.resourcepool.BasicResourcePool$AcquireTask@26f2f761
		com.mchange.v2.resourcepool.BasicResourcePool$AcquireTask@194f1541
		com.mchange.v2.resourcepool.BasicResourcePool$AcquireTask@16fc6b62
		com.mchange.v2.resourcepool.BasicResourcePool$AcquireTask@15edfab8
		com.mchange.v2.resourcepool.BasicResourcePool$AcquireTask@3ae75147
		com.mchange.v2.resourcepool.BasicResourcePool$AcquireTask@28892a87
		com.mchange.v2.resourcepool.BasicResourcePool$AcquireTask@454719db
		com.mchange.v2.resourcepool.BasicResourcePool$AcquireTask@3ef29c65
		com.mchange.v2.resourcepool.BasicResourcePool$AcquireTask@29f9cb2c
Pool thread stack traces:
	Thread[com.mchange.v2.async.ThreadPoolAsynchronousRunner$PoolThread-#0,5,main]
		java.sql.DriverManager.registerDriver(DriverManager.java:280)
		com.mysql.jdbc.Driver.<clinit>(Driver.java:62)
		java.lang.Class.forName0(Native Method)
		java.lang.Class.forName(Class.java:169)
		com.mchange.v2.c3p0.DriverManagerDataSource.ensureDriverLoaded(DriverManagerDataSource.java:100)
		com.mchange.v2.c3p0.DriverManagerDataSource.getConnection(DriverManagerDataSource.java:132)
		com.mchange.v2.c3p0.WrapperConnectionPoolDataSource.getPooledConnection(WrapperConnectionPoolDataSource.java:182)
		com.mchange.v2.c3p0.WrapperConnectionPoolDataSource.getPooledConnection(WrapperConnectionPoolDataSource.java:171)
		com.mchange.v2.c3p0.impl.C3P0PooledConnectionPool$1PooledConnectionResourcePoolManager.acquireResource(C3P0PooledConnectionPool.java:137)
		com.mchange.v2.resourcepool.BasicResourcePool.doAcquire(BasicResourcePool.java:1014)
		com.mchange.v2.resourcepool.BasicResourcePool.access$800(BasicResourcePool.java:32)
		com.mchange.v2.resourcepool.BasicResourcePool$AcquireTask.run(BasicResourcePool.java:1810)
		com.mchange.v2.async.ThreadPoolAsynchronousRunner$PoolThread.run(ThreadPoolAsynchronousRunner.java:547)
	Thread[com.mchange.v2.async.ThreadPoolAsynchronousRunner$PoolThread-#1,5,main]
		java.lang.Class.forName0(Native Method)
		java.lang.Class.forName(Class.java:169)
		com.mchange.v2.c3p0.DriverManagerDataSource.ensureDriverLoaded(DriverManagerDataSource.java:100)
		com.mchange.v2.c3p0.DriverManagerDataSource.getConnection(DriverManagerDataSource.java:132)
		com.mchange.v2.c3p0.WrapperConnectionPoolDataSource.getPooledConnection(WrapperConnectionPoolDataSource.java:182)
		com.mchange.v2.c3p0.WrapperConnectionPoolDataSource.getPooledConnection(WrapperConnectionPoolDataSource.java:171)
		com.mchange.v2.c3p0.impl.C3P0PooledConnectionPool$1PooledConnectionResourcePoolManager.acquireResource(C3P0PooledConnectionPool.java:137)
		com.mchange.v2.resourcepool.BasicResourcePool.doAcquire(BasicResourcePool.java:1014)
		com.mchange.v2.resourcepool.BasicResourcePool.access$800(BasicResourcePool.java:32)
		com.mchange.v2.resourcepool.BasicResourcePool$AcquireTask.run(BasicResourcePool.java:1810)
		com.mchange.v2.async.ThreadPoolAsynchronousRunner$PoolThread.run(ThreadPoolAsynchronousRunner.java:547)
	Thread[com.mchange.v2.async.ThreadPoolAsynchronousRunner$PoolThread-#2,5,main]
		java.lang.Class.forName0(Native Method)
		java.lang.Class.forName(Class.java:169)
		com.mchange.v2.c3p0.DriverManagerDataSource.ensureDriverLoaded(DriverManagerDataSource.java:100)
		com.mchange.v2.c3p0.DriverManagerDataSource.getConnection(DriverManagerDataSource.java:132)
		com.mchange.v2.c3p0.WrapperConnectionPoolDataSource.getPooledConnection(WrapperConnectionPoolDataSource.java:182)
		com.mchange.v2.c3p0.WrapperConnectionPoolDataSource.getPooledConnection(WrapperConnectionPoolDataSource.java:171)
		com.mchange.v2.c3p0.impl.C3P0PooledConnectionPool$1PooledConnectionResourcePoolManager.acquireResource(C3P0PooledConnectionPool.java:137)
		com.mchange.v2.resourcepool.BasicResourcePool.doAcquire(BasicResourcePool.java:1014)
		com.mchange.v2.resourcepool.BasicResourcePool.access$800(BasicResourcePool.java:32)
		com.mchange.v2.resourcepool.BasicResourcePool$AcquireTask.run(BasicResourcePool.java:1810)
		com.mchange.v2.async.ThreadPoolAsynchronousRunner$PoolThread.run(ThreadPoolAsynchronousRunner.java:547)


> Contention for DriverManager when initializing multiple datasources 
> --------------------------------------------------------------------
>
>                 Key: DBCP-272
>                 URL: https://issues.apache.org/jira/browse/DBCP-272
>             Project: Commons Dbcp
>          Issue Type: Bug
>    Affects Versions: 1.2.2
>         Environment: Java HotSpot(TM) 64-Bit Server VM (1.6.0-b105 mixed mode) on Linux
>            Reporter: Adrian Woodhead
>         Attachments: catalina.out.stuck2
>
>
> This issue has been discussed in the commons user's mailing list between myself, Simon Kitching and Phil Steitz. 
> In summary:
> I have a webapp deployed in tomcat containing 3 pooled datasources which are managed by Spring. The webapp starts up OK and is immediately hit by a load of a few hundred requests a second. It seems to handle a few hundred request and then just locks up entirely and stops responding entirely. Attached is a stack trace obtained by doing kill -3 when in this state. After discussion on the mailing list I changed the datasources to be non-lazy initialised in spring but the issue still occurs. 
> Simon Kitching said:
> "The first thread is trying to initialise a postgresql driver and register it with DriverManager. The driver registration is being triggered from a static initialiser block on the postgresql driver class, so is executing from within the Class.forName method (and therefore the postgresql driver Class object is locked by this thread).
> The second thread is trying to initialise a mysql driver and register it with DriverManager. Again, the driver registration is being triggered from a static initialiser block on the mysql driver class, so the mysql driver Class object is locked by this thread).
> But in both cases, the DriverManager needs to be initialised before anything can be registered. The first thread appears to have run first, triggering the initialisation process, and the second thread is blocked waiting for initialisation of DriverManager to complete before it registers the mysql driver. 
> <snip/>
> Possibly dbcp should call DriverManager.getDrivers() internally on startup to avoid this race... "

-- 
This message is automatically generated by JIRA.
-
You can reply to this email to add a comment to the issue online.