C3P0单连接池配置下maxConnectionAge参数的行为咨询
Answer to Your c3p0 Connection Behavior Question
Hey there! Let me break down exactly what happens with your c3p0 setup based on real-world usage:
When you configure minPoolSize=1, maxPoolSize=1, and maxConnectionAge=30 seconds, c3p0 will destroy the existing connection after 30 seconds and create a new one to replace it. Here's the detailed breakdown:
- First,
maxConnectionAgesets the maximum lifespan of any connection in the pool, starting from the moment the connection is created. Once a connection hits this 30-second threshold, c3p0 marks it for destruction. - Since your
minPoolSizeis set to 1, the pool is required to always maintain at least one active connection to meet the minimum requirement.- If the connection is sitting idle in the pool when it reaches 30 seconds old, c3p0's background maintenance thread will spot the expired connection, destroy it, and immediately spin up a new connection to keep the pool at the minimum size.
- If the connection is currently being used by your application when it hits the 30-second mark, c3p0 won't destroy it until it's returned to the pool. As soon as it's handed back, it gets destroyed right away, and a fresh connection is created immediately to maintain the
minPoolSizeof 1.
The core thing to remember here is that the minPoolSize rule means the pool can never be empty—so the expired connection will always be replaced with a new one once it's time to retire it.
内容的提问来源于stack exchange,提问作者Amar Malik
相关产品推荐
相关产品推荐

