Announcement Announcement Module
Collapse
No announcement yet.
How do I create a org.apache.commons.dbcp.PoolableConnection Page Title Module
Move Remove Collapse
X
Conversation Detail Module
Collapse
  • Filter
  • Time
  • Show
Clear All
new posts

  • How do I create a org.apache.commons.dbcp.PoolableConnection

    I've written a web application using spring/hibernate/tapestry to talk to MS SQL server 7. It does not use connection pooling and the resulting performance is very poor.

    I know I need a connection pool and the connection pool I want to use is
    org.apache.commons.dbcp.PoolableConnection.

    The problem is that I do not know how to configure this in an application context. Does anybody have any examples ?

    Thanks

  • #2
    Here's my config for using commons pooling, though it doesn't use PoolableConnection (at least not explicitly).
    It needs to start with a non-pooled data source (bean cpmsDS)
    and gives you a pooled data source (pooledDS).
    I wouldn't claim this is an optimal solution, but it works for me:

    Code:
        <bean id="cpmsDS" class="org.springframework.jdbc.datasource.DriverManagerDataSource">
            <property name="driverClassName"><value>your.driver.classname</value></property>
            <property name="url"><value>yourDatabaseUrl</value></property>
            <property name="username"><value>yourUsername</value></property>
            <property name="password"><value>yourPassword</value></property>
        </bean>
    
        <bean id="pool" class="org.apache.commons.pool.impl.GenericObjectPool">
            <property name="minEvictableIdleTimeMillis"><value>300000</value></property>
            <property name="timeBetweenEvictionRunsMillis"><value>60000</value></property>
        </bean>
    
        <bean id="dsConnectionFactory" class="org.apache.commons.dbcp.DataSourceConnectionFactory">
            <constructor-arg><ref bean="cpmsDS"/></constructor-arg>
        </bean>
    
        <bean id="poolableConnectionFactory" class="org.apache.commons.dbcp.PoolableConnectionFactory">
            <constructor-arg index="0"><ref bean="dsConnectionFactory"/></constructor-arg>
            <constructor-arg index="1"><ref bean="pool"/></constructor-arg>
            <constructor-arg index="2"><null/></constructor-arg>
            <constructor-arg index="3"><null/></constructor-arg>
            <constructor-arg index="4"><value>false</value></constructor-arg>
            <constructor-arg index="5"><value>true</value></constructor-arg>
        </bean>
    
        <bean id="pooledDS" class="org.apache.commons.dbcp.PoolingDataSource" depends-on="poolableConnectionFactory">
            <constructor-arg><ref bean="pool"/></constructor-arg>
        </bean>

    Comment


    • #3
      Thanks. Login now works faster

      Comment

      Working...
      X