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
Over 2 million developers have joined DZone.
Log In / Join
Refcards Trend Reports
Events Video Library
Refcards
Trend Reports

Events

View Events Video Library

Trending

  • Start Coding With Google Cloud Workstations
  • Is Agile Right for Every Project? When To Use It and When To Avoid It
  • Event-Driven Architectures: Designing Scalable and Resilient Cloud Solutions
  • Testing SingleStore's MCP Server

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
Likes (7)
Comment
Save
Tweet
Share
12.5K Views

Join the DZone community and get the full member experience.

Join For Free

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

The likes didn't load as expected. Please refresh the page and try again.

ABOUT US

  • About DZone
  • Support and feedback
  • Community research
  • Sitemap

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 100
  • Nashville, TN 37211
  • [email protected]

Let's be friends: