I'm just learning about connection pools, and I was wondering if there's ever any reason to set maxIdle
> maxActive
.
This is my understanding:
Idle connections are connections that have been created and are waiting to be used. It becomes an active connection once a client borrows it.
minIdle
determines the number of initial connections to create in a pool.
When a client tries to use the pool, an idle connection is given. If there are no available idle connections, the pool will create one. When an idle connection becomes an active connection, if the number of idle connections fall below minIdle
, the pool will create connections until there are at least minIdle
idle connections. When a client is finished with an active connection, the connection becomes an idle connection again.
This means the number of idle connections can grow, so maxIdle
prevents the connection pool from having too many idle connections. Since maxActive
caps the number of connections that can be borrowed, there is no need to have a maxIdle
> maxActive
.