C3P0 APPARENT DEADLOCK when my tomcat launch

when I start my project tomcat or tar, my project throws an error: APPARENT DEADLOCK

I think that the error caused by c3p0 cannot connect my database, I change my xml and replace the domain name with the ip of my database, and then start the project!

I use a listener before my c3p0 work, and I can get the correct domain name and ip, I can not find the reason for 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@14313f f (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@17e107 c 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) 
+5
source share
2 answers

It seems that you found the reason: you have problems with DNS, so attempts to search your database by name freeze, and connecting to your database by IP address is fine. The c3p0 messages you see indicate that attempts to get connections from the database hang (that is, they do not succeed and fail with the exception). In the end, those who hung the tasak exhaust c3p0 thread pool, and you see APPARENT DEADLOCK warnings.

The setting suggested by user1516873, statementCacheNumDeferredCloseThreads, is useful when you see statement-related tasks that cause deadlocks, but are unlikely to help in your case. You are trying to connect pools to database connections.

The main thing you need to do is debug the DNS problem on your web application server. Try tools like nslookup or dig and see if you can search the database server by name and if the results come immediately or if you freeze in the search. From what you described, you are likely to find a problem there.

+3
source

As described in the documentation: http://www.mchange.com/projects/c3p0/ , section Setting up the report pool

If statementCacheNumDeferredCloseThreads is greater than zero, the Record Pool will be deferred physically close () to cached requests until its parent connection is used by some client or internal (for example, test) pool itself. For some JDBC drivers (especially Oracle), attempts to close the expression are frozen if the parent connection is used. This parameter defaults to 0. Set it to a positive value if you observe "APPARENT DEADLOCKS" to complete the task of closing the connection. Almost always, this value should be the same: if you need more than one, the topic devoted exclusively to the destruction of Applications should probably set maxStatements and / or maxStatementsPerConnection to higher values ​​so that you do not refuse cached statements too quickly.

+1
source

All Articles