Hibernate使用C3P0的连接池,并队c3p0配置。
1.导入c3p0.jar包,hibernate自带的包,也可以在网上下载一个。
2.Hibernate的配置文件,hibernate.cfg.xml中增加:
<property name="c3p0.acquire_increment">1</property>
<property name="c3p0.idle_test_period">100</property>
<property name="c3p0.max_size">5</property>
<property name="c3p0.max_statements">0</property>
<property name="c3p0.min_size">2</property>
<property name="c3p0.timeout">90</property>
<property name="c3p0.preferredTestQuery ">select 1 from user where id=1</property>
<property name="c3p0.idleConnectionTestPeriod ">18000</property>
<property name="c3p0.maxIdleTime">25000</property>
<property name="c3p0.testConnectionOnCheckout">true</property>
3.重新启动tomcat,问题解决。
重新启动tomcat之后,可以会提示一下警告
WARN C3P0ConnectionProvider:210 - Both hibernate-style property 'hibernate.c3p0.max_size' and c3p0-style property 'c3p0.max_size' have been set in hibernate.properties. Hibernate-style property 'hibernate.c3p0.max_size' will be used and c3p0-style property 'c3p0.max_size' will be ignored!
解决方法为:
将
"c3p0.max_size"
替换成
"hibernate.c3p0.max_size"
网上找了好多
不知道这个方案是否真的管用
暂时没有报错