Hibernate自带的连接池算法相当不成熟。 它只是为了让你快些上手,并不适合用于产品系统或性能测试中。 出于最佳性能和稳定性考虑你应该使用第三方的连接池。只需要用特定连接池的设置替换 hibernate.connection.pool_size即可。这将关闭Hibernate自带的连接池。 例如, 你可能会想用C3P0.
C3P0是一个随Hibernate一同分发的开源的JDBC连接池, 它位于lib目录下。 如果你设置了hibernate.c3p0.*相关的属性, Hibernate将使用 C3P0ConnectionProvider来缓存JDBC连接。 如果你更原意使用Proxool, 请参考发 行包中的hibernate.properties并到Hibernate网站获取更多的信息。
这是一个使用C3P0的hibernate.properties样例文件(来自Hibernate包中etc目录下):
###########################
### C3P0 Connection Pool###
###########################
#hibernate.c3p0.max_size 2
#hibernate.c3p0.min_size 2
#hibernate.c3p0.timeout 5000
#hibernate.c3p0.max_statements 100
#hibernate.c3p0.idle_test_period 3000
#hibernate.c3p0.acquire_increment 2
#hibernate.c3p0.validate false
在hibernate.cfg.xml文件里面加入如下的配置:
<!-- 最大连接数 -->
<property name="hibernate.c3p0.max_size">20</property>
<!-- 最小连接数 -->
<property name="hibernate.c3p0.min_size">5</property>
<!-- 获得连接的超时时间,如果超过这个时间,会抛出异常,单位毫秒 ***-->
<property name="hibernate.c3p0.timeout">120</property>
<!-- 最大的PreparedStatement的数量 -->
<property name="hibernate.c3p0.max_statements">100</property>
<!-- 每隔120秒检查连接池里的空闲连接 ,单位是秒-->
<property name="hibernate.c3p0.idle_test_period">120</property>
<!-- 当连接池里面的连接用完的时候,C3P0一下获取的新的连接数 -->
<property name="hibernate.c3p0.acquire_increment">2</property>
<!-- 每次都验证连接是否可用 -->
<property name="hibernate.c3p0.validate">true</property>
完整示例如下(hibernate.properties):
hibernate.connection.driver_class = org.postgresql.Driver
hibernate.connection.url = jdbc:postgresql://localhost/mydatabase
hibernate.connection.username = myuser
hibernate.connection.password = secret
hibernate.c3p0.min_size=5
hibernate.c3p0.max_size=20
hibernate.c3p0.timeout=1800
hibernate.c3p0.max_statements=50
hibernate.dialect = org.hibernate.dialect.PostgreSQLDialect
分享到:
相关推荐
(hibernate调用C3p0)hibernate.cfg.xml
hibernate 配置 C3P0 连接池
c3p0Jar包,Hibernate配置数据源必备,包含xml配置文件
hibernate3.3版本后,hibernate配置c3p0需要的jar包,如果没有这个包,可能会报异常,找不到provider-class的那个类
C3P0是一个开源的JDBC连接池,它实现了数据源和JNDI绑定,支持JDBC3规范和JDBC2的标准扩展。目前使用它的开源项目有Hibernate、Spring等。 适合人群:正在学习使用数据库连接池 里面的配置文件直接可用,少走弯路,...
配置了tomcat之后发现jndi好简单啊,可是碰到了hibernate该怎么做呢,本例详细解析
Hibernate 下配置连接池解决多连接的问题
c3p0-0.9.2.1.jar&&hibernate-c3p0-4.0.0.Final[1].jar&&mchange-commons-java-0.2.3.4.jar
hibernate c3p0实例源码,配置hibernate使用c3p0连接池测试demo
Hibernate支持第三方的...例如,配置C3P0时的provider_class有Hibernate2环境下使用net.sf.hibernate.connection.C3P0ConnectionProvider,在Hibernate3环境下使用org.hibernate.connection.C3P0ConnectionProvider。
Hibernate框架,默认推荐使用C3P0作为连接池实现,一个开源的连接池。 拷贝c3p0的jar到lib目录 (c3p0-0.9.5.2.jar , mchange-commons-java-0.2.12.jar) 把配置文件c3p0.xmla拷贝到src目录下(配置文件名一定不能修改...
一个hibernate数据源的c3p0配置,希望对你有帮助
c3p0 hibernat缓存 详细配置
Hibernate4的全套jar包,及hbm.xml(模板)+hibernate.cfg.xml(模板)+c3p0(全套)+ojdbc14.jar
c3p0详细配置描了属性的作用使用方法,怎样和hibernate使用
例如,配置C3P0时的provider_class有Hibernate2环境下使用net.sf.hibernate.connection.C3P0ConnectionProvider,在Hibernate3环境下使用org.hibernate.connection.C3P0ConnectionProvider。 下面是Hibernate环境下...
Hibernate支持第三方的...例如,配置C3P0时的provider_class有Hibernate2环境下使用net.sf.hibernate.connection.C3P0ConnectionProvider,在Hibernate3环境下使用org.hibernate.connection.C3P0ConnectionProvider。
c3p0在spring中的配置及所需jar包,一般用hibernate时用c3p0比较稳定一些。
将两个包考入lib目录即可使用 包括c3p0-0.9.1.jar和hibernate-c3p0-4.1.11.Final.jar
NULL 博文链接:https://12345678.iteye.com/blog/718264