标签:hibernate
三种连接都是以连接MySQl为例。<!-- JDBC驱动程序 --> <property name="connection.driver_class">org.gjt.mm.mysql.Driver</property> <property name="connection.url">jdbc:mysql://localhost:3306/struts?useUnicode=true&characterEncoding=GBK</property> <!-- 数据库用户名 --> <property name="connection.username">root</property> <!-- 数据库密码 --> <property name="connection.password">8888</property>
只需在hibernate.cfg.xml中加入 <property name="c3p0.min_size">5</property> <property name="c3p0.max_size">30</property> <property name="c3p0.time_out">1800</property> <property name="c3p0.max_statement">50</property> 还有在classespath中加入c3p0-0.8.4.5.jar
在hibernate.cfg.xml中加入 <property name="dbcp.maxActive">100</property> <property name="dbcp.whenExhaustedAction">1</property> <property name="dbcp.maxWait">60000</property> <property name="dbcp.maxIdle">10</property> <property name="dbcp.ps.maxActive">100</property> <property name="dbcp.ps.whenExhaustedAction">1</property> <property name="dbcp.ps.maxWait">60000</property> <property name="dbcp.ps.maxIdle">10</property> 还有在classespath中加入commons-pool-1.2.jar 和commons-dbcp-1.2.1.jar.
在hibernate.cfg.xml中加入 <property name="proxool.pool_alias">pool1</property> <property name="proxool.xml">ProxoolConf.xml</property> <property name="connection.provider_class">net.sf.hibernate.connection.ProxoolConnectionProvider</property>
<?xml version="1.0" encoding="utf-8"?> <!-- the proxool configuration can be embedded within your own application's. Anything outside the "proxool" tag is ignored. --> <something-else-entirely> <proxool> <alias>pool1</alias> <!--proxool只能管理由自己产生的连接--> <driver-url>jdbc:mysql://localhost:3306/struts?useUnicode=true&characterEncoding=GBK</driver-url> <driver-class>org.gjt.mm.mysql.Driver</driver-class> <driver-properties> <property name="user" value="root"/> <property name="password" value="8888"/> </driver-properties> <!-- proxool自动侦察各个连接状态的时间间隔(毫秒),侦察到空闲的连接就马上回收,超时的销毁--> <house-keeping-sleep-time>90000</house-keeping-sleep-time> <!-- 指因未有空闲连接可以分配而在队列中等候的最大请求数,超过这个请求数的用户连接就不会被接受--> <maximum-new-connections>20</maximum-new-connections> <!-- 最少保持的空闲连接数--> <prototype-count>5</prototype-count> <!-- 允许最大连接数,超过了这个连接,再有请求时,就排在队列中等候,最大的等待请求数由maximum-new-connections决定--> <maximum-connection-count>100</maximum-connection-count> <!-- 最小连接数--> <minimum-connection-count>10</minimum-connection-count> </proxool> </something-else-entirely>
并在classespath中加入proxool-0.8.3.jar
结论:hibernate配置连接池的3中方式,布布扣,bubuko.com
标签:hibernate
原文地址:http://blog.csdn.net/estelle_belle/article/details/27335187