简体   繁体   中英

Testing Connection pool in Tomcat

I have a JDBC connection pool setup in tomcat server.

在此处输入图像描述 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?

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.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM