1

Our application has multiple modules, each module use its own schema in the same mysql database. Now I need to make different connection pool configurations for each module because of their different db resource consuming nature, i.e. some module may have 20 active connections at a point of time, but others may just have 1 max. I have searched here and other forums, couldn't find a solution, just this topic is not about multi-tenancy or multi-database, all schemas are in the same db.

Here's the config we have:

<bean id="dataSource" class="our.own.package.RoutingDataSource"> <!-- RoutingDataSource extends spring AbstractDataSource -->
    <property name="master" ref="masterDS"/>
</bean>
<bean id="abstractDataSource" abstract="true">
    <property name="driverClass" value="com.mysql.jdbc.Driver" />
    <property name="initialPoolSize" value="@initial.pool.size@" />
    <property name="minPoolSize" value="@min.pool.size@" />
    <property name="maxPoolSize" value="@max.pool.size@" /> <!-- I want to have different configs for each module in our application -->
</bean>
<bean id="masterDS" class="com.mchange.v2.c3p0.ComboPooledDataSource" parent="abstractDataSource">
    <property name="jdbcUrl" value="jdbc:mysql://@host@/" />
    <property name="user" value="@user@" />
    <property name="password" value="@pwd@" />
    <property name="dataSourceName" value="@dbName@" />
</bean>

So now I have two questions:

1) Is it possible to have different connection pool configurations for one datasource in Spring?

2) If I have to go with the multiple datasource way(one datasource for one module), is implementing Spring's AbstractRoutingDataSource the correct way to go?

Thank you!

1 Answers1

0

Ad.1 Your data source is in the fact connection pool so you want to have multiple pools on the top of another pool. You can do it but you will face many other problems.

Ad.2. Yes definitely. You already have RoutingDataSource so this one should be implementation of AbstractRoutingDataSource. Probably you already have logic there to determine current the data source routing key which should be used to do the lookup.

Jaro
  • 1
  • 1