servicemix,oracle数据源,连接池,最大连接数

时间:2014-10-24 13:15:22

标签: jdbc connection-pooling apache-karaf apache-servicemix

我试图在servcemix 4.4.1中配置连接池。我创建了一个oracle数据源对象,并设置了user,password,url等属性。我在我的smx中将以下xml部署为osgi服务。

这是我的数据源配置:

    <blueprint xmlns="http://www.osgi.org/xmlns/blueprint/v1.0.0"> 

     <bean id="dataSource" class="oracle.jdbc.pool.OracleDataSource"> 
     <property name="URL" value="jdbc:oracle:thin:@connection:url"/> 
 <property name="user" value="****"/> 
 <property name="password" value="*****"/>


 </bean> 

 <service interface="javax.sql.DataSource" ref="dataSource"> 
 <service-properties> 
 <entry key="osgi.jndi.service.name" value="oracleds"/> 
 </service-properties> 
 </service> 
 </blueprint> 

数据源对象是成功创建的,我可以使用我的包中的jndi查找来检索对象。

现在我想应用连接池,我需要声明&#34;最大连接数&#34;。请建议我如何声明最大号码。上面的xml中的连接

提前致谢。

2 个答案:

答案 0 :(得分:1)

您可以选择两种方式:

答案 1 :(得分:0)

以下是我的blueprint.xml示例:

<blueprint     xmlns="http://www.osgi.org/xmlns/blueprint/v1.0.0"
    xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
    xmlns:ext="http://aries.apache.org/blueprint/xmlns/blueprint-ext/v1.0.0"
    xmlns:cm="http://aries.apache.org/blueprint/xmlns/blueprint-cm/v1.0.0"
    xsi:schemaLocation=
            "http://www.osgi.org/xmlns/blueprint/v1.0.0 http://www.osgi.org/xmlns/blueprint/v1.0.0/blueprint.xsd"
    default-activation="eager">

    <cm:property-placeholder id="server.placeholder" persistent-id="test.datasource">
        <cm:default-properties>
            <cm:property name="driverClassName" value="oracle.jdbc.pool.OracleDataSource" />
            <cm:property name="validationQuery" value="SELECT 1 FROM DUAL" />
            <cm:property name="defaultReadOnly" value="false" />
            <cm:property name="defaultAutoCommit" value="true" />
            <cm:property name="maxActive" value="100" />
            <cm:property name="whenExhaustedAction" value="2" />
            <cm:property name="maxWait" value="-1" />
            <cm:property name="maxIdle" value="8" />
            <cm:property name="minIdle" value="1" />
            <cm:property name="testOnBorrow" value="true" />
            <cm:property name="testOnReturn" value="true" />
            <cm:property name="timeBetweenEvictionRunsMillis" value="-1" />
            <cm:property name="numTestsPerEvictionRun" value="3" />
            <cm:property name="minEvictableIdleTimeMillis" value="1800000" />
            <cm:property name="testWhileIdle" value="false" />
            <cm:property name="softMinEvictableIdleTimeMillis" value="-1" />
            <cm:property name="lifo" value="true" />
        </cm:default-properties>
    </cm:property-placeholder>

    <bean id="dataSource" class="org.apache.commons.dbcp.BasicDataSource" destroy-method="close">
      <property name="driverClassName" value= "${driverClassName}" />
      <property name="url" value="jdbc:oracle:thin:@${db.host}:${db.port}:${db.instance}" />
      <property name="username" value="${db.user}" />
      <property name="password" value="${db.password}" />
      <property name="maxIdle" value="1" />
    </bean>

    <bean id="connectionFactory" class="org.apache.commons.dbcp.DataSourceConnectionFactory">
      <argument ref="dataSource" />
    </bean>

    <bean id="connectionPool" class="org.apache.commons.pool.impl.GenericObjectPool" >
      <argument><null/></argument>
      <argument value="${maxActive}" />
      <argument value="${whenExhaustedAction}" />
      <argument value="${maxWait}" />
      <argument value="${maxIdle}" />
      <argument value="${minIdle}" />
      <argument value="${testOnBorrow}" />
      <argument value="${testOnReturn}" />
      <argument value="${timeBetweenEvictionRunsMillis}" />
      <argument value="${numTestsPerEvictionRun}" />
      <argument value="${minEvictableIdleTimeMillis}" />
      <argument value="${testWhileIdle}" />
      <argument value="${softMinEvictableIdleTimeMillis}" />
      <argument value="${lifo}" />
    </bean>

    <bean id="pooledConnectionFactory" class="org.apache.commons.dbcp.PoolableConnectionFactory" >
      <argument ref="connectionFactory" />
      <argument ref="connectionPool" />
      <argument><null/></argument>
      <argument value="${validationQuery}" />
      <argument value="${defaultReadOnly}" />
      <argument value="${defaultAutoCommit}" />
    </bean>

    <bean id="poolingDataSource" class="org.apache.commons.dbcp.PoolingDataSource" depends-on="pooledConnectionFactory">
      <argument ref="connectionPool" />
    </bean>

    <service interface="javax.sql.DataSource" ref="poolingDataSource"> <!--ref="oracleDataSource"-->
        <service-properties>
            <entry key="osgi.jndi.service.name" value="jdbc/testdb"/>
            <entry key="datasource.name" value="jdbc/testdb" />
        </service-properties>
    </service>

</blueprint>

此数据源工作正常。 我认为“maxActive”属性接近你需要的属性。