Configuring connection pool size with guice, mybatis, and c3p0 or bonecp

Supagoat

I'm using Guice/Mybatis to manage and execute my queries to a MySQL database. My class that sets up the connection and extends MyBatisModule contains these relevant bits:

Properties myBatisProperties = new Properties();
myBatisProperties.setProperty("c3p0.maxPoolSize", "5");
myBatisProperties.setProperty("c3p0.initialPoolSize", "5");
bindDataSourceProviderType(C3p0DataSourceProvider.class);
bindTransactionFactoryType(JdbcTransactionFactory.class);
addMapperClass(getMapperClass());
Names.bindProperties(binder(), myBatisProperties);
bind(getBindServiceClass()).to(getBindServiceToClass());

When I configure either using c3p0 or bonecp using its properties of bonecp.maxConnectionsPerPartition and bonecp.partitionCount, and the appropriate DataSourceProvider.class in place of C3p0DataSourceProvider, both c3p0 and bonecp ignore my max connections configuration and just open (and hold open) a new connection for every query until mysql runs out of available connections.

When I use the default mybatis pool provider PooledDataSourceProvider and its properties, mybatis.pooled.maximumActiveConnections and mybatis.pooled.maximumIdleConnections, it respects my configuration and pools connections correctly.

What am I doing wrong?

Further documentation for this is available at http://mybatis.github.io/guice/datasources.html

Supagoat

It looks like the problem was due to the my creating a new injector every time. Specifically this line:

Injector injector = Guice.createInjector(new MyDAOPoolModule()); return injector.getInstance(MyDAOService.class);

If instead I make the injector a singleton, it only creates the one pool.

Collected from the Internet

Please contact [email protected] to delete if infringement.

edited at
0

Comments

0 comments
Login to comment

Related

From Dev

if c3p0 is configured, will connection.pool_size be ignored

From Dev

Tomcat connection pool with MyBatis

From Dev

Set SQLite connection properties in c3p0 connection pool

From Dev

C3P0 connection pool gives connection timeout error with this configuration

From Dev

Will a connection always be checked in to a c3p0 connection pool, when closing the entity manager?

From Dev

Detect invalid credentials being passed to c3p0 connection pool

From Dev

C3P0 Connection Pool Getting java.sql.SQLException: No suitable driver exception

From Dev

C3P0 Managed connection pool could not acquire a resource from its primary or factory resource

From Dev

How to use C3P0 in a spring boot hibernate multi tenant application to manage connection pool?

From Dev

C3p0 trying to create a new connection pool and failing with ClassNotFoundException

From Dev

Spring, Hibernate C3P0 Connection Pool, physical connections not closed

From Dev

c3p0 connection pooling, DataSources factory, how do I close the pool?

From Dev

How to find which application created each c3p0 connection pool?

From Dev

Handling connection pool exhaustion and avoiding deadlock in Hibernate/C3P0

From Dev

c3p0 not releasing connection when max_size reached

From Java

High Hibernate Connection Pool Size

From Dev

Sequelize default connection pool size

From Dev

Python Requests URLLib3 Connection Pool Size

From Dev

SQLConnection pool size and active connection count in C#

From Dev

Is "Tomcat 7 JDBC Connection Pool" good enough for production? And how is it compare to BoneCP?

From Dev

Mongo Connection Pooling(Changing the size of connection pool)

From Dev

Connections checking in c3p0 pool

From Dev

Issues with Hibernate and C3p0 pool

From Dev

Why limit DB Connection Pool Size in SQLAlchemy?

From Dev

Determining what to Raising Max Pool Size to for my Connection Pool

From Dev

How configure connection existence check in C3P0?

From Dev

c3p0 connection Pooling error - Oracle RAC

From Dev

Sometimes Hibernate can not get connection by C3P0

From Dev

c3p0 piling Connection objects

Related Related

  1. 1

    if c3p0 is configured, will connection.pool_size be ignored

  2. 2

    Tomcat connection pool with MyBatis

  3. 3

    Set SQLite connection properties in c3p0 connection pool

  4. 4

    C3P0 connection pool gives connection timeout error with this configuration

  5. 5

    Will a connection always be checked in to a c3p0 connection pool, when closing the entity manager?

  6. 6

    Detect invalid credentials being passed to c3p0 connection pool

  7. 7

    C3P0 Connection Pool Getting java.sql.SQLException: No suitable driver exception

  8. 8

    C3P0 Managed connection pool could not acquire a resource from its primary or factory resource

  9. 9

    How to use C3P0 in a spring boot hibernate multi tenant application to manage connection pool?

  10. 10

    C3p0 trying to create a new connection pool and failing with ClassNotFoundException

  11. 11

    Spring, Hibernate C3P0 Connection Pool, physical connections not closed

  12. 12

    c3p0 connection pooling, DataSources factory, how do I close the pool?

  13. 13

    How to find which application created each c3p0 connection pool?

  14. 14

    Handling connection pool exhaustion and avoiding deadlock in Hibernate/C3P0

  15. 15

    c3p0 not releasing connection when max_size reached

  16. 16

    High Hibernate Connection Pool Size

  17. 17

    Sequelize default connection pool size

  18. 18

    Python Requests URLLib3 Connection Pool Size

  19. 19

    SQLConnection pool size and active connection count in C#

  20. 20

    Is "Tomcat 7 JDBC Connection Pool" good enough for production? And how is it compare to BoneCP?

  21. 21

    Mongo Connection Pooling(Changing the size of connection pool)

  22. 22

    Connections checking in c3p0 pool

  23. 23

    Issues with Hibernate and C3p0 pool

  24. 24

    Why limit DB Connection Pool Size in SQLAlchemy?

  25. 25

    Determining what to Raising Max Pool Size to for my Connection Pool

  26. 26

    How configure connection existence check in C3P0?

  27. 27

    c3p0 connection Pooling error - Oracle RAC

  28. 28

    Sometimes Hibernate can not get connection by C3P0

  29. 29

    c3p0 piling Connection objects

HotTag

Archive