How to Get Connection Pool Size in Spring Boot?
Connection pooling is a technique used to improve the performance of database-driven applications by reusing existing connections instead of creating new ones. In Spring Boot, connection pooling can be configured using the spring.datasource.hikari.* properties. The size of the connection pool is determined by the spring.datasource.hikari.maximumPoolSize property.
Steps to Get Connection Pool Size in Spring Boot
1. Open the application.properties file and add the following line:
2. This will set the maximum number of connections that can be created in the connection pool to 10.
3. To get the current size of the connection pool, you can use the HikariDataSource class provided by Spring Boot:
HikariDataSource dataSource = (HikariDataSource) context.getBean("dataSource"); int poolSize = dataSource.getMaximumPoolSize(); System.out.println("Connection Pool Size: " + poolSize);
4. This will print out the current size of the connection pool.