Connection Pool Exhaustion in JDBC
Fast recall
Quick revision
Core answer
Whether you know pool exhaustion leads to blocking then timeout, not unlimited growth.
Believing the pool grows past its max under load.
Connect chronic exhaustion to leaks/slow queries and the need to monitor pool metrics.
Interview-ready guide
Interview answer
If ten pool connections are active and an eleventh request needs one, it waits. A completed transaction closes its logical Connection, allowing the pool to hand it to a waiter. If a query is blocked on a lock longer than the acquisition timeout, several callers may time out even though no connection was leaked. Metrics need to separate connection acquisition, usage, and database execution time.
Connection Pool Exhaustion in JDBC
Direct Answer
When the pool has reached maximumPoolSize and every connection is borrowed, another getConnection call waits for one to return. If none becomes available before connectionTimeout, Hikari throws a SQLTransientConnectionException. This is bounded waiting/backpressure. The cause may be long queries, long transactions, database blocking, too much request concurrency, leaks, or a genuinely undersized tested pool.
Code Example
// maximumPoolSize = 3; all 3 checked out and held:
Connection c1 = pool.getConnection();
Connection c2 = pool.getConnection();
Connection c3 = pool.getConnection(); // pool now empty
// a 4th concurrent caller blocks here, waiting up to connectionTimeout,
// then throws SQLTransientConnectionException if nothing is returned:
// Connection c4 = pool.getConnection(); // waits ~30s, then times out
c1.close(); // returning one unblocks a waiting caller
Common Mistakes & Pitfalls
- Thinking the pool grows past max: it blocks, it doesn't expand.
- Not closing connections: leaks permanently shrink available capacity.
- Slow queries holding connections: they cause exhaustion even with no leak.
- No monitoring: track active/idle/pending to spot exhaustion early.
Check your understanding
Answer these without looking back at the article.
- What is connection pooling and why is it critical for production Java applications?
- What is HikariCP and how do you configure it in Spring Boot?
- What is a connection leak in JDBC and how do you prevent it?
Looking for a structured roadmap?
Every module on this page is also part of the full Java backend interview track.