I want to know if my understanding of the Tomcat Connection pool lifecycle is correct.
For example, I have the following settings:
<Resource name="jdbc/appname" auth="Container"
type="javax.sql.DataSource" maxActive="100"
maxIdle="30" maxWait="1000"
username="username"
initialSize = "5"
password="password"
driverClassName="jdbc.driver.name"
url="jdbc:protocol://hostname:port/dbname"/>
When my application is deployed it has 5 connections(initial size), when all these connections are busy tomcat create and add to pool a new connection(6), this new connections limit are maxActive(100) and when 101 requests are coming, tomcat will wait 1000 ms(maxWait) and then throw TimeOutException. In some period of time only 40 connections are busy, and when one of them is free it will be destroyed because pool almost has 30(maxIdle) free connections. Am I right?
And if I am, then what is the purpose of setting maxIdle and maxActive to different values?
In some period of time only 40 connections are busy, and when one of them is free it will be destroyed because pool almost has 30(maxIdle) free connections.
When 40 connections are busy and one of them becomes free, it becomes idle, resulting in the following state:
39 busy connections
1 idle connection
The maxActive
setting specifies the max amount of connections that may exist, in any state, at any given time. The maxIdle
setting is more specific and only determines the max amount of idle connections.
Say that maxActive
is set to 100 and at a certain point all these connections exist and are busy, then if a couple of minutes later they are all idle, you don't want to keep these 100 idle connections, because they are not doing anything besides consuming resources.
This is where the maxIdle
setting comes into play. It tells the connection pool to not hold more than an X amount of idle connections. If it is set to 30, then 70 connections of the 100 idle connections are dropped.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With