When the concurrency is large, the c3p0 connection pool displays the following exception:
Caused by: Java. SQL. sqlexception: an attempt by a client to checkout a connection has timed out. at COM. mchange. v2. SQL. sqlutils. tosqlexception (sqlutils. java: 106) at com. mchange. v2. SQL. sqlutils. tosqlexception (sqlutils. java: 65) at com. mchange. v2.c3p0. impl. c3p0pooledconnectionpool. checkoutpooledconnection (c3p0pooledconnectionpool. java: 527) at com. mchange. v2.c3p0. impl. abstractpoolbackeddatasource. getconnection (abstractpoolbackeddatasource. java: 128) at Org. springframework. JDBC. datasource. datasourceutils. dogetconnection (performanceutils. java: 113) at Org. springframework. JDBC. datasource. datasourceutils. getconnection (performanceutils. java: 79 )... 5 morecaused by: COM. mchange. v2.resourcepool. timeoutexception: a client timed out while waiting to acquire a resource from -- timeout at awaitavailable () at com. mchange. v2.resourcepool. basicresourcepool. awaitavailable (basicresourcepool. java: 1317) at com. mchange. v2.resourcepool. basicresourcepool. prelimcheckoutresource (basicresourcepool. java: 557) at com. mchange. v2.resourcepool. basicresourcepool. checkoutresource (basicresourcepool. java: 477) at com. mchange. v2.c3p0. impl. c3p0pooledconnectionpool. checkoutpooledconnection (c3p0pooledconnectionpool. java: 525 )... 8 more
The exception analysis for this part is as follows:
On the Internet, it is often said that c3p0 has a bug. When c3p0 closes both statement and connection, or closes them for a short time, sometimes the connection is not closed because some preparedstatement is still in cached state. In this way, many connections are not actually closed, and the connection pool is exhausted, the above exception will occur. The solution is to disable the cache, that is, to disable c3p0. max_statements is set to 0, so that no cached preparedstatement exists, and c3p0 is set. idle_test_period is smaller than c3p0. timeout.
If you have time to look back, read the source code study. Now, we can solve this problem first.