连接池
作用: 管理连接;提升连接的利用效率!
常用的连接池: C3P0连接池
Hibernate 自带的也有一个连接池,且对C3P0连接池也有支持!
Hbm 自带连接池:
只维护一个连接,比较简陋。
可以查看hibernate.properties文件查看连接池详细配置:
#################################
### Hibernate Connection Pool ###
#################################
hibernate.connection.pool_size 1 【Hbm 自带连接池: 只有一个连接】
###########################
### C3P0 Connection Pool### 【Hbm对C3P0连接池支持】
###########################
#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
【Hbm对C3P0连接池支持,核心类】
告诉hib使用的是哪一个连接池技术。
#hibernate.connection.provider_class org.hibernate.connection.C3P0ConnectionProvider
Hibernate.cfg.xml 中增加连接池相关配置:
<property name="hibernate.connection.provider_class">org.hibernate.connection.C3P0ConnectionProvider</property>,
这一句用于指定Hibernate的连接提供方式,如果没有将不会使用c3p0作为Hibernate的连接池。