官方网站:http://proxool.sourceforge.net/
目前最新的版本是版本0.9.0RC3(2007-01-10);
你也可以通过cvs下载最新的源代码:
cvs -d:pserver:[email protected]:/cvsroot/proxool login
cvs -z3 -d:pserver:[email protected]:/cvsroot/proxool co proxool
首先编写配置文件proxool.xml
<proxool><alias>qxgldb</alias><driver-url>
jdbc:jtds:sqlserver://localhost:1433/wmjqxgl;SelectMethod=cursor;charset=GBK;tds=8.0;lastupdatecount=true
</driver-url><driver-class>net.sourceforge.jtds.jdbc.Driver</driver-class><driver-properties><property name="user" value="sa"><property name="password" value="sa"></property><house-keeping-sleep-time>30000</house-keeping-sleep-time><!-- 配置为30秒, proxool自动侦察各个连接状态的时间间隔(毫秒),侦察到空闲的连接就马上回收,超时的销毁。 --><!-- 保留线程处于睡眠状态的最长时间,house keeper 的职责就是检查各个连接的状态,并判断是否需要销毁或者创建. --><!-- How long the house keeping thread sleeps for (milliseconds). Defaults to
30000 (30 seconds) --><simultaneous-build-throttle>20</simultaneous-build-throttle><!-- 同时最大连接数 --><!-- This is the maximum number of connections we can be building at any one time. That is,
the number of new connections that have been requested but aren't yet available for use.(这个参数不可用)
Defaults to 10. --><house-keeping-sleep-time>3000</house-keeping-sleep-time><!-- 检测线程睡眠多长时间。How long the house keeping thread sleeps for (milliseconds). Defaults to
30000 (30 seconds) --><maximum-active-time>180000</maximum-active-time><!-- 配置了3分钟,如果housekeeper 检测到某个线程的活动时间大于这个数值.它将会杀掉这个线程.所以确认一下你的服务器的带宽.然后定一个合适的值.默认是5分钟. --><!-- maximum-active-time,配置了3分钟,一旦达到最大的连接数,只有这个指令才能够杀死连接线程。 --><maximum-new-connections>20</maximum-new-connections><!--注意:这个参数暂时未实现。 指因未有空闲连接可以分配而在队列中等候的最大请求数,超过这个请求数的用户连接就不会被接受。 --><!-- This is the maximum number of connections we can be building at any one time. That is,
the number of new connections that have been requested but aren't yet available for use.
Defaults to 10. --><maximum-connection-lifetime>3600000</maximum-connection-lifetime><!-- 任何空闲连接超过1小时,那么将被remove。Any idle connections older than this will be removed by the housekeeper (milliseconds).
Defaults to 4 * 60 * 60 * 1000 (4 hours). --><prototype-count>5</prototype-count><!-- 最少保持的空闲连接数。如果少于这个连接数,那么新的连接将被建立。 --><!-- If there are fewer than this number of connections available then we will build some more
(assuming the maximum-connection-count is not exceeded). Defaults to zero. --><maximum-connection-count>12</maximum-connection-count><!-- 允许最大连接数,超过了这个连接,再有请求时,就排在队列中等候,最大的等待请求数由maximum-new-connections决定 --><minimum-connection-count>5</minimum-connection-count><!-- 最小连接数 --><house-keeping-test-sql>select getdate()</house-keeping-test-sql><!-- 测试连接使用的sql --><recently-started-threshold>60000</recently-started-threshold><!-- This helps us determine whether the pool status. As long as at least one connection was
started within this threshold (milliseconds) or there are some spare connections available
then we assume the pool is up. Defaults to 60 seconds. --><overload-without-refusal-lifetime>60000</overload-without-refusal-lifetime><!-- This helps us determine the pool status. If we have refused a connection within this threshold
(milliseconds) then we are overloaded. Defaults to 60 seconds. --><verbose>false</verbose><!-- Either false (quiet) or true (loud). Default is false. --><trace>true</trace><!-- If true then every execution will be logged. Default is false. --><statistics>1m,15m,1d</statistics><!-- The sample length when taking statistical information, comma-delimited. For example: '10s,15m'
would mean take samples every 10 seconds and every 15 minutes. Valid units are s(econds),
m(inutes), h(ours) and d(ays). Default is no statistics --><statistics-log-level>INFO</statistics-log-level><!-- Whether statistics are logged as they are produced. Range: DEBUG, INFO, WARN, ERROR, FATAL.
Not to be confused with the level used with the general log. You have to configure that
separately. Default is no logging --></property><pre></pre></driver-properties></proxool>
然后修改web.xml
<!-- 加载proxool连接池的配置信息 -->
<servlet><servlet-name>ServletConfigurator</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><!-- 连接池监控的servlet --><servlet><servlet-name>ProxoolAdmin</servlet-name><servlet-class>
org.logicalcobwebs.proxool.admin.servlet.AdminServlet
</servlet-class><init-param><param-name>output</param-name><param-value>full</param-value></init-param></servlet><servlet-mapping><servlet-name>ProxoolAdmin</servlet-name><url-pattern>/ProxoolAdmin</url-pattern></servlet-mapping>
访问连接池监控页面的时候,可能会出现乱码。
解决办法:找到org.logicalcobwebs.proxool.admin.servlet.AdminServlet.java
将对应的java代码更改为下面的代码即可。(因为就是时间乱码)
/**
* dd-MMM-yyyy HH:mm:ss
*/
private static final DateFormat DATE_FORMAT = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
如何通过proxool连接池来获取链接呢?
核心代码如下:
public Connection getConnection() {
Connection connection = null;
//org.logicalcobwebs.proxool.ProxoolDriver
try {
Class.forName("org.logicalcobwebs.proxool.ProxoolDriver");
connection = DriverManager.getConnection("proxool.qxgldb");
} catch (SQLException e) {
log.error("通过Proxool连接池获取数据库连接出错!", e);
} catch (ClassNotFoundException e) {
log.error("加载数据库驱动出错,未找到相应的class。",e);
}
return connection;
}
如何与spring结合呢?我的是spring2.0.8
<!-- 通过proxool来配置数据源 -->
<bean id="dataSource"
class="org.springframework.jdbc.datasource.DriverManagerDataSource">
<property name="driverClassName"
value="org.logicalcobwebs.proxool.ProxoolDriver" />
<property name="url"
value="proxool.qxgldb" />
<!--
<property name="username" value="sa" />
<property name="password" value="sa" /> -->
</bean>
log4j.xml的配置
<appender name="LogToFileProxool"
class="org.apache.log4j.RollingFileAppender">
<param name="File" value="d:/logs/proxool.log" />
<param name="MaxFileSize" value="1MB" />
<param name="MaxBackupIndex" value="10" />
<layout class="org.apache.log4j.PatternLayout">
<param name="ConversionPattern"
value="%-5p (%C:%L) %d{yyyy-MM-dd_HH:mm:ss}- %m%n" />
</layout>
</appender>
<logger name="org.logicalcobwebs.proxool" additivity="false">
<level value="DEBUG" />
<appender-ref ref="LogToFileProxool" />
</logger>
如何与润乾报表结合呢?
<reportconfig><jdbc-ds-configs><jdbc-ds-config><name>dsqxglnew</name><db-type>2</db-type><connection-url>proxool.qxgldb</connection-url><driver-class>org.logicalcobwebs.proxool.ProxoolDriver</driver-class><user-name>sa</user-name><password>sa</password><db-charset>GBK</db-charset><client-charset>GBK</client-charset></jdbc-ds-config></jdbc-ds-configs><config><name>logConfig</name><value>/WEB-INF/runqianReportLog.properties</value></config><config><name>license</name><value>runqianWindowServer.lic</value></config><config><name>reportFileHome</name><value>/reportFiles</value></config><config><name>semanticsFile</name><value>/WEB-INF/runqianSemanticFile.xml</value></config><!--
<config>
<name>JNDIPrefix</name>
<value>java:</value>
</config>
<config>
<name>dataSource</name>
<value>dsqxglnew,SQLSVR,GBK,0;</value>
</config>
<config>
<name>jspCharset</name>
<value>GBK</value>
</config>
--><config><name>alwaysReloadDefine</name><value>yes</value></config><config><name>cachedParamsTimeout</name><value>120</value></config><config><name>cachedReportDir</name><value>D:/logs</value></config><config><name>cachedIdPrefix</name><value>A</value></config><config><name>cachedReportTimeout</name><value>30</value></config><config><name>maxCellNum</name><value></value></config><config><name>maxConcurrentForReport</name><value>9999</value></config><config><name>maxWaitForReport</name><value>9999</value></config><config><name>maxWaitTimeForReport</name><value>9999</value></config><config><name>appUrlPrefix</name><value></value></config><config><name>errorPage</name><value>/myErrorPage.jsp</value></config></reportconfig>