"apparent deadlocks"Q名词解释是说c3p0拿到链接之后Q最l用之后没有返回到pool,D死链失败。经q在stack Overflow?https://stackoverflow.com/questions/3730844/c3p0-apparent-deadlock-when-the-threads-are-all-empty.发现增加一个statementCacheNumDeferredCloseThreads该参数的定义Q就可以避免q个问题?/p>
l过查看官方文Qhttp://www.mchange.com/projects/c3p0/#statementCacheNumDeferredCloseThreads
解释Q如果把该Dq?Qstatement的缓存就会自动跟t当前可用的connections,如果没有再用Q就会自动销毁掉。如果需要另外的U程来专门销毁缓存的statement,则还需要设|maxStatements与maxStatementsPerConnection?/p>
再脓一个官方的说明Q?/p>
c3p0 implements transparent PreparedStatement pooling as defined by the JDBC spec. Under some circumstances, statement pooling can dramatically improve application performance. Under other circumstances, the overhead of statement pooling can slightly harm performance. Whether and how much statement pooling will help depends on how much parsing, planning, and optimizing of queries your databases does when the statements are prepared. Databases (and JDBC drivers) vary widely in this respect. It's a good idea to benchmark your application with and without statement pooling to see if and how much it helps.
You configure statement pooling in c3p0 via the following configuration parameters:
statementCacheNumDeferredCloseThreads
maxStatementsis JDBC's standard parameter for controlling statement pooling.maxStatementsdefines the total numberPreparedStatementsa DataSource will cache. The pool will destroy the least-recently-used PreparedStatement when it hits this limit. This sounds simple, but it's actually a strange approach, because cached statements conceptually belong to individual Connections; they are not global resources. To figure out a size formaxStatementsthat does not "churn" cached statements, you need to consider the number offrequently usedPreparedStatements in your application,and multiply that by the number of Connections you expect in the pool (maxPoolSizein a busy application).
maxStatementsPerConnectionis a non-standard configuration parameter that makes a bit more sense conceptually. It defines how many statements each pooled Connection is allowed to own. You can set this to a bit more than the number ofPreparedStatementsyour applicationfrequentlyuses, to avoid churning.
If either of these parameters are greater than zero, statement pooling will be enabled. If both parameters are greater than zero, both limits will be enforced. If only one is greater than zero, statement pooling will be enabled, but only one limit will be enforced.
大概意思就是这两个Q有一个值如果大?Qc3p0的statement pool׃发生作用?/p>
以上所有的配置都是Zc3p0的最新版本。PS一下,q是2015q的JAR?/p>
通过引入最新的C3P0包,另外增加了两D配|,U上观察两天Q问题解冟?/p>
最后打个小q告QJAVA世界最快的JDBCq接池,?a target="_blank" style="color: #3194d0; text-decoration-line: none;">HikariCP莫属。已l甩c3p0好几个街角,有图有真像?/p>