DZone
Thanks for visiting DZone today,
Edit Profile
  • Manage Email Subscriptions
  • How to Post to DZone
  • Article Submission Guidelines
Sign Out View Profile
  • Post an Article
  • Manage My Drafts
Newsletter
Log In / Join
Refcards Trend Reports
Events Video Library
Refcards
Trend Reports

Events

View Events Video Library

Trending

  • How to Submit a Post to DZone
  • Data Integration Landscape 2026: Event Streaming, API, and Batch in the Era of Agentic AI
  • OpenCode: Setting Up an Open-Source AI Coding Assistant
  • YAGNI in the Age of AI Coding

Draft This article hasn't been published, so readers can't see it.

In moderation This article is waiting for review, so readers can't see it yet.

Deleted This article has been deleted, so readers can't see it.

Understanding the Database Connection Pool (DBCP) Properties

Read here to understand which database connection property is being used in which scenario. The clarity in this aspect will make it easy to tune these values.

By 
Diwakar Grandhi user avatar
Diwakar Grandhi
·
Apr. 16, 22 · Analysis
Post on X (opens in a new tab) Share on LinkedIn (opens in a new tab)
12.9K Views

Join the DZone community Save articles, join the discussion, and download Refcards and Trend Reports with a free account.

Join for free Already a member? Log in

Database Connection Pool Library

Recently, I faced an issue related to a very high load on the database layer. The database was having too many connections in parallel. I had to review my application’s database connection pool (DBCP) properties very closely. Since I was dealing with legacy code, I needed to understand the value assigned to each property and also analyze whether it is relevant for the present-day load or not. As I started looking at the properties, their values, and the consequent implications, I was able to find a decent explanation in the tomcat documentation. However, I wasn’t able to immediately map each property to the scenario where it will be used.

Since we were using Apache tomcat’s JDBC connection pool, I started reading the source code to get a better understanding. I was able to get a lot of clarity by going through the ConnectionPool class. As I didn’t find any easy resource to understand the same, I am summarizing my understanding in the form of simple flowcharts. I hope this will help others in a similar situation.

I am not covering every property. I looked at the major properties such as, initialSize , maxActive , maxWait , maxIdle , timeBetweenEvictionRunsMillis , removeAbandoned , removeAbandonedTimeout , and minEvictableIdleTimeMillis .

Of these, initialSizeis the simplest. It is the number of connections created by the Connection Pool Manager at the start. If it is not defined, the Connection Pool Manager will create 10 threads by default.

For the other properties, I have recognized three scenarios where they will be used. Let’s go through each scenario and understand how these properties are used.

Scenario 1: Get a Data Source Connection

It involves the usage of maxActive (default value = 100) and maxWait (default value = 30 seconds).

Scenario 1: Get a Data Source Connection from the Pool

Scenario 2: A Data Source Connection Is Released by the Application Thread

It involves the usage of maxIdle property. The default value of maxIdle is the value assigned to maxActive. If maxActive is not set, we set the same default value of 100 to both these properties.

Scenario 2: A Data Source Connection Is Released by the Application Thread

Scenario 3: Pool Cleaner Run

Pool Cleanup is performed at regular intervals to maintain the connections. It takes care of the abandoned connections as well as the idle connections.

It involves the usage of timeBetweenEvictionRunsMillis (default value = 5 seconds), removeAbandoned (false by default), removeAbandonedTimeout (default value = 60 seconds), minIdle (default value = value of initialSize. In case it isn’t defined, both are set to 10), and minEvictableIdleTimeMillis (default value = 60 seconds) properties.

Scenario 3: Pool Cleaner Run

Note: There are different implementations for the database connection pool. The code referred to in this article is an implementation by Apache Tomcat. For folks who are interested in the alternatives, Apache Commons has an implementation as well.

Published at DZone with permission of Diwakar Grandhi. See the original article here.

Opinions expressed by DZone contributors are their own.

Partner Resources

×

Comments

Likes

Loading

The next likes didn't load. Please try again.

The likes didn't load

Please try again in a moment.

See who liked this

Log in or join DZone for free to see who liked this article.

Log in Join for free
  • RSS
  • X
  • Facebook

ABOUT US

  • About DZone
  • Support and feedback
  • Community research

ADVERTISE

  • Advertise with DZone

CONTRIBUTE ON DZONE

  • Article Submission Guidelines
  • Become a Contributor
  • Core Program
  • Visit the Writers' Zone

LEGAL

  • Terms of Service
  • Privacy Policy

CONTACT US

  • 3343 Perimeter Hill Drive
  • Suite 215
  • Nashville, TN 37211
  • [email protected]

Let's be friends:

  • RSS
  • X
  • Facebook