c3p0
1樓 2008-10-18
在使用C3P0的過程中出現(xiàn)了好多錯誤.最長見就是死鎖,占用資源比較大.
對于死鎖問題http://japi.javaeye.com/blog/243702.找到了解決方案(不能完全保證,但在負載測試中,還沒有出現(xiàn)問題)
問題關(guān)鍵是參數(shù)的設(shè)置
<!--JDBC的標(biāo)準(zhǔn)參數(shù),用以控制數(shù)據(jù)源內(nèi)加載的PreparedStatements數(shù)量。但由于預(yù)緩存的statements
屬于單個connection而不是整個連接池。所以設(shè)置這個參數(shù)需要考慮到多方面的因素。
如果maxStatements與maxStatementsPerConnection均為0,則緩存被關(guān)閉。Default: 0-->
<property name="maxStatements">100</property>
<!--maxStatementsPerConnection定義了連接池內(nèi)單個連接所擁有的最大緩存statements數(shù)。Default: 0 -->
<property name="maxStatementsPerConnection"></property>
解決的方法是:
來源于:http://forum.hibernate.org/viewtopic.php?p=2386237
http://forum.hibernate.org/viewtopic.php?t=947246&start=0&postdays=0&postorder=asc&highlight=apparent+deadlock+c3p0&sid=6fcfab70cff3588bf010914df8dbbb90
http://www.mchange.com/projects/c3p0/index.html#c3p0_properties
對于死鎖問題http://japi.javaeye.com/blog/243702.找到了解決方案(不能完全保證,但在負載測試中,還沒有出現(xiàn)問題)
問題關(guān)鍵是參數(shù)的設(shè)置
引用
<!--JDBC的標(biāo)準(zhǔn)參數(shù),用以控制數(shù)據(jù)源內(nèi)加載的PreparedStatements數(shù)量。但由于預(yù)緩存的statements
屬于單個connection而不是整個連接池。所以設(shè)置這個參數(shù)需要考慮到多方面的因素。
如果maxStatements與maxStatementsPerConnection均為0,則緩存被關(guān)閉。Default: 0-->
<property name="maxStatements">100</property>
<!--maxStatementsPerConnection定義了連接池內(nèi)單個連接所擁有的最大緩存statements數(shù)。Default: 0 -->
<property name="maxStatementsPerConnection"></property>
解決的方法是:
引用
In hibernate.cfg.xml:
<property name="hibernate.c3p0.max_statements">0</property>
In c3p0.properties:
c3p0.maxStatements=0
c3p0.maxStatementsPerConnection=100
<property name="hibernate.c3p0.max_statements">0</property>
In c3p0.properties:
c3p0.maxStatements=0
c3p0.maxStatementsPerConnection=100
來源于:http://forum.hibernate.org/viewtopic.php?p=2386237
http://forum.hibernate.org/viewtopic.php?t=947246&start=0&postdays=0&postorder=asc&highlight=apparent+deadlock+c3p0&sid=6fcfab70cff3588bf010914df8dbbb90
http://www.mchange.com/projects/c3p0/index.html#c3p0_properties
2樓 LifeFree 2009-05-04
唉,早看到別人說要maxStatements設(shè)置為0,就是沒怎么用c3p0,不知道具體情況。
前段時間在一個事務(wù)里多加了條sql語句,原來并發(fā)沒問題的,后來發(fā)現(xiàn)性能很低。查了很久才發(fā)現(xiàn)是死鎖了,又搞了很久才想到是c3p0的問題。
前段時間在一個事務(wù)里多加了條sql語句,原來并發(fā)沒問題的,后來發(fā)現(xiàn)性能很低。查了很久才發(fā)現(xiàn)是死鎖了,又搞了很久才想到是c3p0的問題。