c3p0
1樓 2008-10-18
在使用C3P0的過(guò)程中出現(xiàn)了好多錯(cuò)誤.最長(zhǎng)見就是死鎖,占用資源比較大.
對(duì)于死鎖問(wèn)題http://japi.javaeye.com/blog/243702.找到了解決方案(不能完全保證,但在負(fù)載測(cè)試中,還沒(méi)有出現(xiàn)問(wèn)題)
問(wèn)題關(guān)鍵是參數(shù)的設(shè)置
<!--JDBC的標(biāo)準(zhǔn)參數(shù),用以控制數(shù)據(jù)源內(nèi)加載的PreparedStatements數(shù)量。但由于預(yù)緩存的statements
屬于單個(gè)connection而不是整個(gè)連接池。所以設(shè)置這個(gè)參數(shù)需要考慮到多方面的因素。
如果maxStatements與maxStatementsPerConnection均為0,則緩存被關(guān)閉。Default: 0-->
<property name="maxStatements">100</property>
<!--maxStatementsPerConnection定義了連接池內(nèi)單個(gè)連接所擁有的最大緩存statements數(shù)。Default: 0 -->
<property name="maxStatementsPerConnection"></property>
解決的方法是:
來(lái)源于: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
對(duì)于死鎖問(wèn)題http://japi.javaeye.com/blog/243702.找到了解決方案(不能完全保證,但在負(fù)載測(cè)試中,還沒(méi)有出現(xiàn)問(wèn)題)
問(wèn)題關(guān)鍵是參數(shù)的設(shè)置
引用
<!--JDBC的標(biāo)準(zhǔn)參數(shù),用以控制數(shù)據(jù)源內(nèi)加載的PreparedStatements數(shù)量。但由于預(yù)緩存的statements
屬于單個(gè)connection而不是整個(gè)連接池。所以設(shè)置這個(gè)參數(shù)需要考慮到多方面的因素。
如果maxStatements與maxStatementsPerConnection均為0,則緩存被關(guān)閉。Default: 0-->
<property name="maxStatements">100</property>
<!--maxStatementsPerConnection定義了連接池內(nèi)單個(gè)連接所擁有的最大緩存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
來(lái)源于: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
唉,早看到別人說(shuō)要maxStatements設(shè)置為0,就是沒(méi)怎么用c3p0,不知道具體情況。
前段時(shí)間在一個(gè)事務(wù)里多加了條sql語(yǔ)句,原來(lái)并發(fā)沒(méi)問(wèn)題的,后來(lái)發(fā)現(xiàn)性能很低。查了很久才發(fā)現(xiàn)是死鎖了,又搞了很久才想到是c3p0的問(wèn)題。
前段時(shí)間在一個(gè)事務(wù)里多加了條sql語(yǔ)句,原來(lái)并發(fā)沒(méi)問(wèn)題的,后來(lái)發(fā)現(xiàn)性能很低。查了很久才發(fā)現(xiàn)是死鎖了,又搞了很久才想到是c3p0的問(wèn)題。