首先翻译一下官方文档中对idle-timeout和max-lifetime的说明:
idle-timeout
官方说明:This property controls the maximum amount of time that a connection is allowed to sit idle in the pool. This setting only applies when minimumIdle
is defined to be less than maximumPoolSize
. Idle connections will not be retired once the pool reaches minimumIdle
connections. Whether a connection is retired as idle or not is subject to a maximum variation of +30 seconds, and average variation of +15 seconds. A connection will never be retired as idle before this timeout. A value of 0 means that idle connections are never removed from the pool. The minimum allowed value is 10000ms (10 seconds). Default: 600000 (10 minutes)
部分翻译:这个属性控制连接池中空闲连接的最大空闲时间,只有当连接池中连接数量大于最小连接数量(minimumIdle
)时会生效
max-lifetime
官方说明:This property controls the maximum lifetime of a connection in the pool. An in-use connection will never be retired, only when it is closed will it then be removed. On a connection-by-connection basis, minor negative attenuation is applied to avoid mass-extinction in the pool. We strongly recommend setting this value, and it should be several seconds shorter than any database or infrastructure imposed connection time limit. A value of 0 indicates no maximum lifetime (infinite lifetime), subject of course to the idleTimeout
setting. The minimum allowed value is 30000ms (30 seconds). Default: 1800000 (30 minutes)
部分翻译:这个属性控制连接池中一个连接的最大生存时间,当一个连接的生存时间大于这个值且没有正在被使用时,将会被关掉
区别
max-lifetime控制连接的总的生命周期,无论当前连接数是否大于最小连接数量,都会关掉生命周期完结的连接,idle-timeout只控制空闲且大于最小连接数量的那部分连接