Why Spring Boot 2 Picks HikariCP: Speed, Simplicity, and Reliability Explained

This article compiles and translates key information about HikariCP, detailing why Spring Boot 2 adopts it as the default JDBC pool, comparing its performance and stability against BoneCP, C3P0, Tomcat and Druid, and providing practical configuration steps for quick integration.

Programmer DD
Programmer DD
Programmer DD
Why Spring Boot 2 Picks HikariCP: Speed, Simplicity, and Reliability Explained

Spring Boot 2 Default Database Connection Pool

The default pool in Spring Boot 2 has switched from Tomcat to HikariCP. If you explicitly set spring.datasource.type to Hikari in a Tomcat application, the override can be removed.

Why Choose HikariCP?

HikariCP is a newer, high‑performance JDBC connection pool that claims to be the fastest, outperforming other pools such as BoneCP, C3P0, and Tomcat. Its author also created the high‑performance JSON parser HikariJSON.

Key selling points are its tiny size (≈130 KB) and the fact that Spring Boot 2 officially supports it.

Benchmark data from the HikariCP author shows that it significantly outperforms C3P0, Tomcat, and others in methods like DataSource.getConnection(), Connection.close(), PreparedStatement, and Statement.execute(). The results are illustrated below:

These benchmarks also explain why the BoneCP author stopped maintaining the project and recommends HikariCP instead.

Optimizations that Make HikariCP Fast

Bytecode minimisation : The compiled bytecode is trimmed to the smallest possible size, allowing more code to fit in CPU caches.

Optimised proxies and interceptors : HikariCP’s Statement proxy contains only about 100 lines of code, roughly one‑tenth of BoneCP’s.

Custom array type (FastStatementList) : Replaces ArrayList to avoid range‑check overhead on every get() call.

Custom concurrent collection (ConcurrentBag) : A lock‑less structure that offers better concurrent read/write performance than standard Java queues.

Other BoneCP‑specific fixes : Includes research on methods that exceed a CPU time slice, though details are not disclosed.

Reason 1 – Code Size

Fewer lines of code generally mean higher execution efficiency and lower bug probability. The following chart compares the code size of several pools:

Reason 2 – Reputation

User feedback is overwhelmingly positive, as shown in the image below:

Reason 3 – Speed

Third‑party speed tests confirm HikariCP’s superiority:

Reason 4 – Stability

Stability tests under connection‑drop scenarios show HikariCP handling failures more gracefully than alternatives:

Reason 5 – Reliability

When the database becomes unreachable, HikariCP waits the configured timeout (5 s) and then throws a SQLException. Other pools either hang for minutes (C3P0) or return invalid connections (Tomcat, BoneCP). The reliability ranking is illustrated below:

How HikariCP Achieves Its Speed

HikariCP uses the Javassist library to generate lightweight dynamic proxies, resulting in far fewer bytecode instructions than JDK proxies. The proxy factory source (simplified) is shown below:

Key optimisations include:

ConcurrentBag : A lock‑less collection inspired by C# that outperforms LinkedBlockingQueue and LinkedTransferQueue. It uses a combination of ThreadLocal and CopyOnWriteArrayList to minimise contention and false sharing.

FastList : A trimmed‑down List implementation that removes range checks on get() and iterates from the tail on remove(), making statement removal faster.

HikariCP vs. Druid

Community comparisons (shown in the images) indicate that HikariCP generally outperforms Druid in raw performance, while Druid offers richer monitoring features.

For detailed issue discussion, see https://github.com/brettwooldridge/HikariCP/issues/232.

Quick Start with Spring Boot 2

Spring Boot 2 uses HikariCP by default, so no extra dependency is required. The following configuration properties are sufficient to get a functional pool:

# JDBC configuration
spring.datasource.driver-class-name=com.mysql.jdbc.Driver
spring.datasource.url=jdbc:mysql://127.0.0.1:3306/datebook?useUnicode=true&characterEncoding=UTF-8&autoReconnect=true&useSSL=false&zeroDateTimeBehavior=convertToNull
spring.datasource.username=root
spring.datasource.password=root
# Hikari specific settings
spring.datasource.type=com.zaxxer.hikari.HikariDataSource
spring.datasource.hikari.minimum-idle=5
spring.datasource.hikari.maximum-pool-size=15
spring.datasource.hikari.auto-commit=true
spring.datasource.hikari.idle-timeout=30000
spring.datasource.hikari.connection-timeout=30000
spring.datasource.hikari.max-lifetime=1800000
spring.datasource.hikari.connection-test-query=SELECT 1

After adding these properties, start the application and the pool will be ready. The startup screenshot is shown below:

References

https://blog.csdn.net/clementad/article/details/46928621

Original Source

Signed-in readers can open the original source through BestHub's protected redirect.

Sign in to view source
Republication Notice

This article has been distilled and summarized from source material, then republished for learning and reference. If you believe it infringes your rights, please contactadmin@besthub.devand we will review it promptly.

javaperformancebackend-developmentSpring BootHikariCPDatabase Connection Pool
Programmer DD
Written by

Programmer DD

A tinkering programmer and author of "Spring Cloud Microservices in Action"

0 followers
Reader feedback

How this landed with the community

Sign in to like

Rate this article

Was this worth your time?

Sign in to rate
Discussion

0 Comments

Thoughtful readers leave field notes, pushback, and hard-won operational detail here.