当前位置:编程学习 > 网站相关 >>

proxool配置详解

Proxool一个数据库连接池框架,提供了对你选择的其它类型的驱动程序的连接池封装。可以非常简单的移植到现存的代码中。

<?xml version=”1.0” encoding=”UTF-8”?>

<something-else-entriely>

       <proxool>

              <alias>dbname</alias><!—数据源的别名-->

              <driver-url>jdbc:oracle:thin:@127.0.0.1:1521:testdb</driver-url><!—url连接串-->

       <driver-class>oracle</driver-class><!—驱动类-->

       <driver-properties>

              <property name=”user” value=”username”/><!—用户名-->

              <property name=”password” value=”password”/><!—密码-->

</driver-properties>

<!—最大连接数(默认5个),超过了这个连接数,再有请求是,就排在队列中等待,最大的等待请求书又maximum-new-connections决定-->

<maximum-connection-count>100</maximum-connection-count>

<!—最小连接数(默认2个)-->

<minimum-connection-count>10</minimum-connection-count>

       <!—proxool自动侦探各个连接状态的时间间隔(毫秒),侦探到空闲的就马上收回,超时的销毁  默认30秒-->

       <house-keeping-sleep-time>90000</house-keeping-sleep-time>

       <!—没有空闲连接可以分配而在队列中等候的最大请求书,超过这个请求数的用户连接就不会被接受-->

       <maximum-new-connections>400</maximum-new-connections>

       <!—最少保持的空闲连接数(默认2个)-->

       <prototype-count>5</prototype-count>

       <!—在使用之前测试-->

       <test-before-use>true</test-before-use>

       <!—用户保持连接的测试语句—>

       <house-keeping-test-sql>select sysdate from dual</house-keeping-test-sql>

</proxool>

</something-else-entriely>

 

配置web.xml

<?xml version="1.0" encoding="UTF-8"?> 

<web-app version="2.4" xmlns="http://java.sun.com/xml/ns/j2ee"

    xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"

    xsi:schemaLocation="http://java.sun.com/xml/ns/j2ee   

    http://java.sun.com/xml/ns/j2ee/web-app_2_4.xsd"> 

<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-name>Admin</servlet-name> 

    <servlet-class>org.logicalcobwebs.proxool.admin.servlet.AdminServlet</servlet-class>

</servlet>

<servlet-mapping>

    <servlet-name>Admin</servlet-name>

   <url-pattern>/admin</url-pattern> 

</servlet-mapping>

<!-- 配置受保护域,只有Tomcat管理员才能察看连接池的信息 --> 

<security-constraint> 

 <web-resource-collection> 

    <web-resource-name>proxool</web-resource-name>

     <url-pattern>/admin</url-pattern>

 </web-resource-collection>

 <auth-constraint>

   <role-name>manager</role-name>

    </auth-constraint>

 </security-constraint>

<login-config>

       <auth-method>BASIC</auth-method>

        <realm-name>proxool manager Application</realm-name>

</login-config>

<security-role>

<description>The role that is required to log in to the Manager Application</description>

<role-name>manager</role-name>

</security-role>

<error-page>

<error-code>401</error-code>

<location>/401.jsp</location>

</error-page>

</web-app>

 

 

ServletConfigurator:加载并初始化proxool.xml文件,因为它是连接数据库的。其他很多模块都用到数据,所以必须首先加载它

load-on-startup:数值越小,就会先被加载初始化

Admin:监控数据库连接池连接情况

//获得数据库的语句

Connection conn = DriverManager.getConnection(“proxool.dbname”);

 

Proxool.xml配置属性说明

Xml代码:

<?xml version="1.0" encoding="ISO-8859-1"?> 

<something-else-entirely xmlns="http://sumthin.else.entirely" xmlns:proxool="The latest version is available at http://proxool.sourceforge.net/xml-namespace"> 

   <proxool:proxool> 

       <proxool:alias>xml-test-ns</proxool:alias> 

       <proxool:driver-url>jdbc:hsqldb:db/test</proxool:driver-url> 

        <proxool:driver-class>org.hsqldb.jdbcDriver</proxool:driver-class> 

        <proxool:driver-properties> 

            <proxool:property name="user" value="sa"/> 

            <proxool:property name="password" value=""/> 

        </proxool:driver-properties> 

        <proxool:house-keeping-sleep-time>40000</proxool:house-keeping-sleep-time> 

        <proxool:house-keeping-test-sql>select CURRENT_DATE</proxool:house-keeping-test-sql> 

        <proxool:maximum-connection-count>10</proxool:maximum-connection-count> 

        <proxool:minimum-connection-count>3</proxool:minimum-connection-count> 

        <proxool:maximum-connection-lifetime>18000000</proxool:maximum-connection-lifetime><!-- 5 hours --> 

        <proxool:simultaneous-build-throttle>5</proxool:simu

补充:综合编程 , 其他综合 ,
CopyRight © 2022 站长资源库 编程知识问答 zzzyk.com All Rights Reserved
部分文章来自网络,