(1) proxool.xml配置文件
<?xml version="1.0" encoding="UTF-8"?>
<something-else-entirely>
<proxool>
<alias>connPool</alias>
<driver-url>jdbc:oracle:thin:logcd/[email protected]:1521:dolphin</driver-url>
<driver-class>oracle.jdbc.driver.OracleDriver</driver-class>
<driver-properties>
<property name="user" value="logcd"/>
<property name="password" value="logcd"/>
</driver-properties>
<house-keeping-sleep-time>90000</house-keeping-sleep-time>
<maximum-new-connections>5</maximum-new-connections>
<prototype-count>5</prototype-count>
<maximum-connection-count>20</maximum-connection-count>
<minimum-connection-count>15</minimum-connection-count>
</proxool>
</something-else-entirely>
配置说明:
alias: 数据库连接别名(程序中需要使用的名称)
driver-url: 数据库驱动
driver-class: 驱动程序类
driver-properties: 数据库的用户和密码
minimum-connection-count: 最小连接数量,建议设置0以上,保证第一次连接时间
maximum-connection-count: 最大连接数量,如果超过最大连接数量则会抛出异常。连接数设置过多,服务器CPU和内存性能消耗很大。
simultaneous-build-throttle: 同时最大连接数
prototype-count: 一次产生连接的数量。 但不能超过最大连接数。
maximum-active-time: 连接最大活动时间 默认5分钟
maximum-connection-lifetime: 连接最大生命时间 默认4小时
house-keeping-sleep-time: 自动侦察各个连接状态的时间间隔(毫秒),侦察到空闲的连接就马上回收,超时的销毁
<!--Test SQL(SELECT getDate()) --> :
<house-keeping-test-sql>select CURRENT_DATE</house-keeping-test-sql>
(2) 在hibernate中使用proxool,hibernate.cfg.xml中的数据库配置
<hibernate-configuration>
<session-factory>
<property name="proxool.pool_alias">DBPool</property>
<property name="proxool.xml">proxool.xml</property>
<property name="connection.provider_class">
org.hibernate.connection.ProxoolConnectionProvider
</property>
<property name="show_sql">true</property>
<property name="dialect">org.hibernate.dialect.Oracle9Dialect</property>
</session-factory>
</hibernate-configuration>
(3) 在spring中使用proxool
<bean id="dataSource" class="org.logicalcobwebs.proxool.ProxoolDataSource" destroy-
method="reset">
<property name="driver" value="com.mysql.jdbc.Driver" />
<property name="driverUrl" value="jdbc:mysql://localhost/activemq?
user=root&password=root" /><!--必须在这里配置用户名/密码,下面的貌似没用-->
<property name="user" value="root" />
<property name="password" value="root" />
<property name="alias" value="jms1" />
<property name="houseKeepingSleepTime" value="90000" />
<property name="prototypeCount" value="5" />
<property name="maximumConnectionCount" value="100" />
<property name="minimumConnectionCount" value="10" />
</bean>
(4) spring + hibernate + proxool
<bean id="sessionFactory" class="org.springframework.orm.hibernate3.LocalSessionFactoryBean">
<property name="hibernateProperties">
<props>
<prop key="hibernate.dialect">org.hibernate.dialect.Oracle9Dialect</prop>
<prop key="hibernate.show_sql">true</prop>
<prop key="hibernate.cglib.use_reflection_optimizer">true</prop>
<prop
key="connection.provider_class">org.hibernate.connection.ProxoolConnectionProvider</prop>
<prop key="hibernate.proxool.xml">proxool.xml</prop>
<prop key="hibernate.proxool.pool_alias">DBPool</prop>
</props>
</property>
.............
</bean>
(5)在ActiveMQ5.x中使用Proxool
<bean id="oracle-ds" class="org.logicalcobwebs.proxool.ProxoolDataSource" destroy-method="reset">
<property name="driver" value="oracle.jdbc.driver.OracleDriver"/>
<property name="driverUrl" value="jdbc:oracle:thin:activemq/[email protected]:1521:orcl"/>
<property name="user" value="activemq"/>
<property name="password" value="activemq"/>
<property name="alias" value="activemq"/>
<property name="prototypeCount" value="5"/>
<property name="maximumConnectionCount" value="20"/>
<property name="minimumConnectionCount" value="10"/>
<property name="maximumActiveTime" value="600000"/>
<property name="trace" value="true"/>
<property name="verbose" value="true"/>
</bean>
不要启用databaseLock,proxool会关闭超时或者使用完毕的连接,这时再去update Lock表会出异常:
<persistenceAdapter>
<jdbcPersistenceAdapter dataDirectory="${activemq.base}/data" dataSource="#oracle-ds" useDatabaseLock="false"/>
</persistenceAdapter>