Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

When does a Hikari pool connections work? - Spring/Spring Boot

I have the below doubts on the Hikari or any database pooling concept.

  1. When does the connection pool gets created?
    Suppose if I have mentioned spring.datasource.hikari.maximum-pool-size=50
    Will it create 50 database instances?

  2. As by default, Spring scopes on classes in singleton, how 50 instances are created?

like image 663
murali Avatar asked Oct 24 '25 10:10

murali


1 Answers

1: A connection pool will be created when the first connection is creating. For example when the first SQL is executed. {@link com.zaxxer.hikari.HikariDataSource#getConnection()}.

This is my case and maybe it's different according the ORM you are using.

Connection instances will be created by the connection pool. {@link com.zaxxer.hikari.pool.HikariPool#poolEntryCreator} {@link com.zaxxer.hikari.pool.HikariPool#postFillPoolEntryCreator}

"spring.datasource.hikari.maximum-pool-size=50" means that the connection pool would not create connection instance more than 50. So it is the limit for connection instance count in connection pool.

2: Spring Bean is singleton by default. But connection instances in the conneciton pool are not "spring bean" and they are created from "new PoolEntry". {@link com.zaxxer.hikari.pool.HikariPool#createPoolEntry}

like image 159
will Avatar answered Oct 26 '25 23:10

will



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!