C3P0 APPARENT DEADLOCK when my tomcat startup

℡╲_俬逩灬. 提交于 2019-12-07 03:16:36

问题


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)

回答1:


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.




回答2:


As described in documentation: http://www.mchange.com/projects/c3p0/, section Configuring Statement Pooling

If statementCacheNumDeferredCloseThreads is greater than zero, the Statement pool will defer physically close()ing cached Statements until its parent Connection is not in use by any client or internally (in e.g. a test) by the pool itself. For some JDBC drivers (especially Oracle), attempts to close a Statement freeze if the parent Connection is in use. This parameter defaults to 0. Set it to a positive value if you observe "APPARENT DEADLOCKS" realted to Connection close tasks. Almost always, that value should be one: if you need more than one Thread dedicated solely to Statement destruction, you probably should set maxStatements and/or maxStatementsPerConnection to higher values so you don't churn through cached Statements so quickly.



来源:https://stackoverflow.com/questions/13008099/c3p0-apparent-deadlock-when-my-tomcat-startup

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!