1、从http://proxool.sourceforge.net/下载proxool,释放proxool.jar到WEB-INF/lib
2、(1)Hibernate:
①、在hibernate.cfg.xml中增加:
<property name="hibernate.proxool.pool_alias">dbpool</property>
<property name="hibernate.proxool.xml">proxool.xml</property>
<property name="connection.provider_class">org.hibernate.connection.ProxoolConnectionProvider</property>
②、在与hibernate.cfg.xml同级目录(src根目录下)增加
proxool.xml文件:
<?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>dbpool</alias>
<!--proxool只能管理由自己产生的连接-->
<driver-url>
jdbc:mysql://localhost:3306/msms
</driver-url>
<driver-class>com.mysql.jdbc.Driver</driver-class>
<driver-properties>
<property name="user" value="sqh" />
<property name="password" value="sqh" />
</driver-properties>
<!-- proxool自动侦察各个连接状态的时间间隔(毫秒),侦察到空闲的连接就马上回收,超时的销毁-->
<house-keeping-sleep-time>90000</house-keeping-sleep-time>
<!-- 最少保持的空闲连接数-->
<prototype-count>5</prototype-count>
<!-- 允许最大连接数,超过了这个连接,再有请求时,就排在队列中等候,最大的等待请求数由maximum-new-connections决定-->
<maximum-connection-count>100</maximum-connection-count>
<!-- 最小连接数-->
<minimum-connection-count>10</minimum-connection-count>
<house-keeping-test-sql>select CURRENT_DATE</house-keeping-test-sql>
</proxool>
</something-else-entirely>
(2)①、在WEB-INF目录下增加proxool.xml文件。
②、配置web.xml
在web.xml中增加: (这个相当于程序中使用JAXPConfigurator.configure("proxool.xml", false)。在Hibernate中不需要这一步)
<!-- 配置初始化servlet,在web容器加载的时候自动加载配置文件,如果不是web程序,这个部分就需要通过开发接口来初始化了 -->
<servlet>
<servlet-name>proxoolInitialServlet</servlet-name>
<servlet-class>org.logicalcobwebs.proxool.configuration.ServletConfigurator</servlet-class>
<init-param>
<param-name>xmlFile</param-name>
<param-value>WEB-INF/proxool.xml</param-value>
</init-param>
<load-on-startup>1</load-on-startup>
</servlet>
3、<!--配置监控servlet,其实如果不想监控的话,可以不配-->
<servlet>
<servlet-name>dbpoolAdmin</servlet-name>
<servlet-class>org.logicalcobwebs.proxool.admin.servlet.AdminServlet</servlet-class>
</servlet>
<servlet-mapping>
<servlet-name>dbpoolAdmin</servlet-name>
<url-pattern>/dbpool</url-pattern>
</servlet-mapping>
4、重起tomcat
5、在程序中调用
Connection con = DriverManager.getConnection("proxool.别名");
posted on 2007-08-10 08:32
cccp21 阅读(599)
评论(0) 编辑 收藏