Subjects

All subjects Django Java Python React Spring Boot JavaScript PHP
Sign Up Free
Interview question

How do you configure database connection pooling in Spring Boot (HikariCP)? स्प्रिंग बूट में डेटाबेस कनेक्शन पूलिंग (HikariCP) को कैसे कॉन्फिगर करें?

Answer

Spring Boot uses HikariCP as the default connection pool when spring-boot-starter-data-jpa or spring-boot-starter-jdbc is on the classpath, since it's fast, lightweight, and auto-configured out of the box — no extra dependency is needed.

Pool behavior is tuned through spring.datasource.hikari.* properties such as maximum-pool-size, minimum-idle, connection-timeout, and idle-timeout. Sizing the pool correctly (often close to the number of available CPU cores times a small factor, rather than an arbitrarily large number) matters more for throughput than simply maximizing pool size.

spring.datasource.hikari.maximum-pool-size=10
spring.datasource.hikari.minimum-idle=5
spring.datasource.hikari.connection-timeout=30000
spring.datasource.hikari.idle-timeout=600000

स्प्रिंग बूट डिफ़ॉल्ट रूप से HikariCP को कनेक्शन पूल के रूप में उपयोग करता है जब spring-boot-starter-data-jpa या spring-boot-starter-jdbc क्लासपाथ पर हो, क्योंकि यह तेज़, हल्का और ऑटो-कॉन्फिगर्ड होता है — किसी अतिरिक्त डिपेंडेंसी की ज़रूरत नहीं पड़ती।

पूल का व्यवहार spring.datasource.hikari.* प्रॉपर्टीज़ जैसे maximum-pool-size, minimum-idle, connection-timeout से ट्यून किया जाता है। पूल का सही आकार तय करना (आमतौर पर उपलब्ध CPU कोर की संख्या के करीब) थ्रूपुट के लिए ज़्यादा मायने रखता है।

spring.datasource.hikari.maximum-pool-size=10
spring.datasource.hikari.minimum-idle=5
spring.datasource.hikari.connection-timeout=30000
spring.datasource.hikari.idle-timeout=600000

Was this answer clear?