"apparent deadlocks"錛氬悕璇嶈В閲婃槸璇碿3p0鎷垮埌閾炬帴涔嬪悗錛屾渶緇堜嬌鐢ㄤ箣鍚庢病鏈夎繑鍥炲埌pool,瀵艱嚧姝婚摼媯嫻嬪け璐ャ傜粡榪囧湪stack Overflow媯绱?https://stackoverflow.com/questions/3730844/c3p0-apparent-deadlock-when-the-threads-are-all-empty.鍙戠幇澧炲姞涓涓猻tatementCacheNumDeferredCloseThreads璇ュ弬鏁扮殑瀹氫箟錛屽氨鍙互閬垮厤榪欎釜闂銆?/p>
緇忚繃鏌ョ湅瀹樻柟鏂囨。錛歨ttp://www.mchange.com/projects/c3p0/#statementCacheNumDeferredCloseThreads
瑙i噴錛氬鏋滄妸璇ュ艱涓鴻秴榪?錛宻tatement鐨勭紦瀛樺氨浼氳嚜鍔ㄨ窡韙綋鍓嶅彲鐢ㄧ殑connections,濡傛灉娌℃湁鍐嶇敤錛屽氨浼氳嚜鍔ㄩ攢姣佹帀銆傚鏋滈渶瑕佸彟澶栫殑綰跨▼鏉ヤ笓闂ㄩ攢姣佺紦瀛樼殑statement,鍒欒繕闇瑕佽緗甿axStatements涓巑axStatementsPerConnection銆?/p>
鍐嶈創涓涓畼鏂圭殑璇存槑錛?/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.
澶ф鎰忔濆氨鏄繖涓や釜錛屾湁涓涓煎鏋滃ぇ浜?錛宑3p0鐨剆tatement pool灝變細鍙戠敓浣滅敤銆?/p>
浠ヤ笂鎵鏈夌殑閰嶇疆閮芥槸鍩轟簬c3p0鐨勬渶鏂扮増鏈侾S涓涓嬶紝榪樻槸2015騫寸殑JAR銆?/p>
閫氳繃寮曞叆鏈鏂扮殑C3P0鍖咃紝鍙﹀澧炲姞浜嗕袱孌甸厤緗紝綰夸笂瑙傚療涓ゅぉ錛岄棶棰樿В鍐熾?/p>
鏈鍚庢墦涓皬騫垮憡錛孞AVA涓栫晫鏈蹇殑JDBC榪炴帴姹狅紝闈?a target="_blank" style="color: #3194d0; text-decoration-line: none;">HikariCP鑾睘銆傚凡緇忕敥c3p0濂藉嚑涓瑙掞紝鏈夊浘鏈夌湡鍍忋?/p>