Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

C3P0 APPARENT DEADLOCK when my tomcat startup

Tags:

java

tomcat

c3p0

when I start up my project by tomcat or resin,my project will throw the error: APPARENT DEADLOCK

I think the error caused by c3p0 can't connect my database, I change my xml and replace the domain name by ip of my database, and then the project start up!

I use a listener before my c3p0 working ,and I can get the correct domain name and ip,I can't find the reason of APPARENT DEADLOCK.

012-10-22 16:53:04 24344    WARN  [Timer-0] com.mchange.v2.async.ThreadPoolAsynchronousRunner:624 - com.mchange.v2.async.ThreadPoolAsynchronousRunner$DeadlockDetector@1e79aa -- APPARENT DEADLOCK!!! Complete Status: 
    Managed Threads: 3
    Active Threads: 3
    Active Tasks: 
        com.mchange.v2.resourcepool.BasicResourcePool$AcquireTask@723a14 (com.mchange.v2.async.ThreadPoolAsynchronousRunner$PoolThread-#0)
        com.mchange.v2.resourcepool.BasicResourcePool$AcquireTask@14313ff (com.mchange.v2.async.ThreadPoolAsynchronousRunner$PoolThread-#1)
        com.mchange.v2.resourcepool.BasicResourcePool$AcquireTask@d5f50d (com.mchange.v2.async.ThreadPoolAsynchronousRunner$PoolThread-#2)
    Pending Tasks: 
        com.mchange.v2.resourcepool.BasicResourcePool$AcquireTask@cb560b
        com.mchange.v2.resourcepool.BasicResourcePool$AcquireTask@17e107c
Pool thread stack traces:
    Thread[com.mchange.v2.async.ThreadPoolAsynchronousRunner$PoolThread-#0,5,main]
        java.net.PlainSocketImpl.socketConnect(Native Method)
        java.net.PlainSocketImpl.doConnect(PlainSocketImpl.java:333)
like image 408
user1764812 Avatar asked Oct 22 '12 09:10

user1764812


1 Answers

It sounds like you've found the cause: you are having DNS problems, so that attempts to lookup your database by name hang, while connecting to your database by IP is fine. The c3p0 messages you are seeing indicate that attempts to acquire Connections from the database are hanging (that is, neither succeeding nor failing with an Exception). Eventually those hung tasak exhaust c3p0's thread pool, and you see APPARENT DEADLOCK warnings.

The setting suggested by user1516873, statementCacheNumDeferredCloseThreads, is useful when you see Statement-related tasks causing deadlocks, but is unlikely to help in your case. You are hanging on attempts by the pool to acquire Connections from the database.

The main thing you ought to do is debug the DNS issue on your web-app server. Try tools like nslookup or dig, and see if you can lookup your database server by name, and if the results come promptly or if you hang in the lookup. From what you describe, you will very likely find a problem there.

like image 72
Steve Waldman Avatar answered Oct 02 '22 22:10

Steve Waldman