Vinayak
Vinayak

Reputation: 67

Testing Connection pool in Tomcat

I have a JDBC connection pool setup in tomcat server.

enter image description here Code 1 takes more time than Code 2. My question is that if connection pool is working. Then it should parallelly open other connections and it should not be taking much time (as I have maxActive= 100 connections). Then what is the point in using connection pool ?

Upvotes: 0

Views: 548

Answers (1)

stdunbar
stdunbar

Reputation: 17435

This makes perfect sense. When you get a Connection from the pool it looks to see if it has a Connection available. If the pool doesn't have an available connection it has to go through the process of obtaining the connection. This is true in both of your examples.

In your first loop, every time you get a connection the pool has to allocate it. Pools get to decide when the "initialSize" is actually allocated - it may not be instantly.

In your second loop, however, you get a Connection and then release it by calling close(). This releases it back to the pool. In this example it's likely you're getting the same connection over and over again.

Upvotes: 1

Related Questions