The code was tested locally and was correct, so I put it on the external server for testing, and an error like this occurred.
com.mchange.v2.async.ThreadPoolAsynchronousRunner -466510 78 [Timer-18] WARN com.mchange.v2.async.ThreadPoolAsynchronousRunner - com.mchange.v2.async.ThreadPoolAsynchronousRunner$DeadlockDetector@1c17bd4 -- APPARENT DEADLOCK!!! Creating emergency threads for unassigned pending tasks!
I was confused when I saw this, what should I do? Why did this happen? Condition?
My answer is:
Because the number of connections to the database is It is limited. Every time the application starts C3p0, it will occupy the database connection to fill the C3p0 connection pool. When the database resources are occupied, a deadlock will be reported because the shared resources cannot be obtained.
Change the maximum number of connections and the number of initial connections in the corresponding configuration file:
Before modification:
<property name="maxPoolSize" value="100" /> <property name="initialPoolSize" value="2" />
After modification:
<property name="maxPoolSize" value="1" /> <property name="initialPoolSize" value="1" />
Redeploy and run, ok!
The above is the detailed content of How to solve the deadlock caused by c3p0. For more information, please follow other related articles on the PHP Chinese website!