Hibernate C3P0连接池经验总结
来源:互联网 发布:mysql ubuntu php 编辑:程序博客网 时间:2024/06/10 07:38
Hibernate自带的连接池算法相当不成熟。 它只是为了让你快些上手,并不适合用于产品系统或性能测试中。 出于最佳性能和稳定性考虑你应该使用第三方的连接池。只需要用特定连接池的设置替换 hibernate.connection.pool_size即可。这将关闭Hibernate自带的连接池。 例如, 你可能会想用C3P0.
Hibernate 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 c3p0 连接池配置
- hibernate C3P0连接池配置
- Hibernate配置C3P0连接池
- hibernate配置c3p0 连接池
- hibernate配置c3p0 连接池
- Hibernate C3P0连接池配置
- hibernate整合C3P0连接池
- Hibernate C3P0 连接池case
- hibernate配置c3p0连接池
- hibernate配置C3P0连接池
- Hibernate配置C3P0连接池
- hibernate使用c3p0连接池
- hibernate配置c3p0连接池
- Hibernate使用c3p0连接池
- Hibernate配置c3p0连接池
- Hibernate使用C3P0的连接池,并队c3p0配置。
- hibernate配置c3p0连接池(lp)
- GIT和repo使用方法,下载android-2.6.29内核
- Java Swing Border(Swing 边框) 归纳
- AJax 返回 json
- Android中更新UI的线程:Thread 、Handler 、Loopper 、TimerTask等
- 1001超级最小公倍数
- Hibernate C3P0连接池经验总结
- extjs 中的日期输入控件不显示数据的解决方法(datefield)
- 基于Spring测试的jndi配置问题
- JFrame打开居中和相关设置 swing 页面设置顺序有关
- ldd(1) is good but objdump(1) is better(转)
- Android开发技巧整理-不段更新中...
- Swing的第一推动力(转载)
- Nutch-default.XML 详细解读
- Linux 设备驱动模型中的class(类)