2013-04-29 45 views
1

我改變我的hibernate.cfg.xml添加新的選項:如何檢查我在休眠狀態下使用c3p0?

<property name="connection.driver_class">org.postgresql.Driver</property> 
     <property name="show_sql">true</property> 
     <property name="connection.url">jdbc:postgresql://localhost:5432/pirates</property> 
     <property name="connection.username">postgres</property> 
     <property name="connection.password">mmm888</property> 

     <property name="dialect">org.hibernate.dialect.PostgreSQLDialect</property> 
     <property name="show_sql">false</property> 
     <property name="hbm2ddl.auto">update</property> 
     <property name="current_session_context_class">thread</property> 

     <property name="hibernate.c3p0.min_size">5</property> 
     <property name="hibernate.c3p0.max_size">200</property> 
     <property name="hibernate.c3p0.timeout">300</property> 
     <property name="hibernate.c3p0.max_statements">50</property> 
     <property name="hibernate.c3p0.idle_test_period">3000</property> 
     <property name="hibernate.generate_statistics">true</property> 

,並在我的項目中添加休眠-c3p0-4.1.4.Final.yar,但我不知道,我使用C3P0。我可以設置hibernate.c3p0.max_size = 2,但Hibernate會繼續創建400個(例如400個)線程 - 如果需要的話。

如何檢查我在hibernate中使用c3p0?

回答

2

你缺少這一行:

<property name="connection.provider_class" 
    value="org.hibernate.connection.C3P0ConnectionProvider"/> 

這告訴Hibernate使用C3P0連接池。

0

檢查here

一般來說,應用程序應該不會有明確的使用,如果在Hibernate提供的 實現的一個配置 的ConnectionProvider。 Hibernate會在內部確定 的ConnectionProvider使用基於以下算法:

如果hibernate.connection.provider_class設置,它的優先級

否則,如果hibernate.connection.datasource設置→使用DataSource

否則如果任何設置由hibernate.c3p0前綴。設置→使用c3p0

否則如果有任何設置由hibernate.proxool前綴。設置→使用 Proxool

否則如果有任何設置由hibernate.hikari加前綴。設置→使用 阿光

否則,如果hibernate.connection.url設置→使用Hibernate的內置 (和不支持的)池

別的→用戶提供的連接

除此以外,最快的檢查方法是進入數據庫服務器並查看是否創建了空閒連接。