Dancrumb
Dancrumb

Reputation: 27579

Can I change the maxActive property of a org.apache.tomcat.jdbc.pool.DataSource dynamically?

I have a webapp running with a Groovy console attached.

I have the following bean configured via XML:

<bean id="dataSource" class="org.apache.tomcat.jdbc.pool.DataSource">
        <property name="driverClassName" value="${db.driverClass}"/>
        <property name="url" value="${db.url}"/>
        <property name="username" value="${db.username}"/>
        <property name="password" value="${db.password}"/>
        <property name="validationQuery" value="${db.validationQuery}" />
        <property name="testOnBorrow" value="true" />
        <property name="testWhileIdle" value="true" />
        <property name="timeBetweenEvictionRunsMillis" value="1800000" />
        <property name="numTestsPerEvictionRun" value="8" />
        <property name="removeAbandoned" value="true"/>
        <property name="logAbandoned" value="true"/>
        <property name="removeAbandonedTimeout" value="60"/>

        <!--connection pooling props -->
        <property name="maxActive" value="${db.maxActive}"/>
        <property name="maxIdle" value="${db.maxIdle}"/>
        <property name="maxAge" value="${db.maxAge}"/>
        <property name="maxWait" value="${db.maxWait}"/>
        <property name="initialSize" value="${db.initialSize}"/>
        <property name="minIdle" value="${db.minIdle}"/>
    </bean>

Via the Groovy console, I can easily call:

appCtx.getBean("dataSource").setMaxActive(someNumber);

where appCtx is my Spring application context.

My question is, will this actually change the connection pool behaviour. All the links I've found seem to focus on initial configuration. I'm trying to modify configuration after the pool is established.

Upvotes: 2

Views: 1540

Answers (2)

EricHenry
EricHenry

Reputation: 26

On inspection of org.apache.tomcat.jdbc.pool.ConnectionPool, it looks like it is checking the maxActive property when fetching a connection from the pool.

So I can't say I know from experience, but it looks like it should work to set this value at Runtime.

Upvotes: 1

David Wolverton
David Wolverton

Reputation: 86

I couldn't find anything in the documentation either, but from looking at the implementation I'm pretty sure it's not intended to support modification after initialization for the following reasons:

  • There is no code written to handle updates to that property, except simply to update the field value.
  • There is a lot of code that does verification of that property in org.apache.tomcat.jdbc.pool.ConnectionPool.init(). None of that code is run if the property is set later.
  • The init() method also allocates at least one queue with a fixed capacity that is never updated elsewhere in the code.

Upvotes: 2

Related Questions