I have the below doubts on the Hikari or any database pooling concept.
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?
As by default, spring scopes on classes in single ton, how 50 instances are created?
Thanks in advance!
CodePudding user response:
Connection pooling
helps reducing in creating database connections everytime a database call is encountered.
Pool
would be nothing but set of connections (ideally active) (Like we have thread pool
), when requested will return one active connection ( or create one for first database request) , instance
would be a misfit word here !
To answer first part of your question, it is initialized during application startup when that spring.datasource.hikari...
property is encountered.
Below link explains this concept well
https://coderstea.in/post/best-practices/jdbc-connection-pooling-explained-with-hikaricp/
CodePudding user response:
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}