Thursday, March 12, 2015

Java - Error - APPARENT DEADLOCK warning in the log

Background:
We have observed the warning in the log file. The java application is using Spring+Hibernate+c3p0 combination for database connectivity.

Error Text: 
WARN v2.async.ThreadPoolAsynchronousRunner:608  - com.mchange.v2.async.ThreadPoolAsynchronousRunner$DeadlockDetector@3dcfc162 -- APPARENT DEADLOCK!!! Creating emergency threads for unassigned pending tasks!

Possible Solutions:

  1. Increase Statement pool size using "maxStatements" (JDBC standard) or set to zero. (see Note-01)
  2. Increase statement pool size using "maxStatementsPerConnection" (users find this more intuitive) or set to zero (see Note-01)
  3. Set "statementCacheNumDeferredCloseThreads". this parameter should almost always be set to 1. (see Note-02)
Solution worked for me:
I used statementCacheNumDeferredCloseThreads=1 and  maxStatementsPerConnection=30

Notes:
  1. Statement caching will be disabled if both "maxStatements" and "maxStatementsPerConnection" are set to zero
  2. Basically, if you need more than one Thread dedicated solely to destroying cached Statements, you should set maxStatements and/or maxStatementsPerConnection so that you don't churn through Statements so quickly.

References:
1. http://www.mchange.com/projects/c3p0/