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.