proxool 連接池配置 (版本0.9.0RC3)

官方網站: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
[XML] view plaincopy
<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
[XML] view plaincopy
<!-- 加載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><pre></pre>
訪問連接池監控頁面的時候,可能會出現亂碼。
解決辦法:找到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連接池來獲取鏈接呢?
核心代碼如下:
[Java] view plaincopy
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;
}<pre></pre>
如何與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>

如何與潤乾報表結合呢?

[XML] view plaincopy
<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>
<pre></pre>
發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章