max-active-time,这个东西 解释 是 active超过这个限制的 线程会被kill掉,
1.
这时候 这个被kill的线程的连接 是被close归还给数据库
还是说 只是被release 到连接池,而连接池 继续保持这个连接
按照监控连接池的页面 表面上观测到的是
active 线程被杀掉后,总共active+avaliable 的总数是没有变的
2.
上面问题的延伸,如果max-active-time 是直接close 回归到数据库,那么
如果业务频繁,先杀掉一批连接 然后 又立马创建一批连接,这样数据库是不是 撑不住
PS:以上所说max-active-time 杀掉的线程 都是 没有正常释放连接的,
正常的业务都是短连接,能够正常的释放
maximum-active-time:表示连接的最大活动时间,即这个连接在指定的时间内没有完成任务(如查询),将
org.logicalcobwebs.proxool.HouseKeeper 是一个后台线程 用于监控线程池的:
[code="java"] if (activeTime > definition.getMaximumActiveTime()) {
// This connection has been active for way too long. We're
// going to kill it :)
connectionPool.removeProxyConnection(proxyConnection, ConnectionListenerIF.MAXIMUM_ACTIVE_TIME_EXPIRED,
"it has been active for too long", ConnectionPool.FORCE_EXPIRY, true);[/code]
1、这段代码用于检查线程池中的每个连接是否超过了最大获得时间
2、如果超过了,会调用connectionPool.removeProxyConnection回收连接
[code="java"]protected void removeProxyConnection(ProxyConnectionIF proxyConnection, int reasonCode, String reason, boolean forceExpiry, boolean triggerSweep) {
// Just check that it is null
if (forceExpiry || proxyConnection.isNull()) {
proxyConnection.setStatus(ProxyConnectionIF.STATUS_NULL);
/* Run some code everytime we destroy a connection */
try {
onDeath(proxyConnection.getConnection(), reasonCode);
} catch (SQLException e) {
log.error("Problem during onDeath (ignored)", e);
}
// The reallyClose() method also decrements the connectionCount.
try {
proxyConnection.reallyClose();
} catch (SQLException e) {
log.error(e);
}
try {
// If we're shutting down then getting a write lock will cause a deadlock
if (isConnectionPoolUp()) {
acquireConnectionStatusWriteLock();
}
proxyConnections.remove(proxyConnection);
} finally {
if (isConnectionPoolUp()) {
releaseConnectionStatusWriteLock();
}
}
if (log.isDebugEnabled()) {
log.debug(displayStatistics() + " - #" + FormatHelper.formatMediumNumber(proxyConnection.getId())
+ " removed because " + reason + ".");
}
if (triggerSweep) {
PrototyperController.triggerSweep(getDefinition().getAlias());
}
} else {
log.error(displayStatistics() + " - #" + FormatHelper.formatMediumNumber(proxyConnection.getId())
+ " was not removed because isNull() was false.");
}
}[/code]
proxyConnection.reallyClose();这句话会关闭真实的connection 并放回到连接池。
一定要注意:我们用了proxool后 返回给我们的connection是一个代理的连接,代理连接执行时再委托给真实的JDBC连接。
HouseKeeper 就是一个后台线程 定期检查连接的健康状况。
max-active-time 你这个是不是 写错了 应该是:maximum-active-time 如果是这个的话
它代表的意思 是最大活动时间(超过此时间线程将被kill,默认为5分钟)
,默认的查询时间为5分钟,如果一个SQL查询5分钟内还没有返回结果,那么将会出现
WARN [ABC] proxool.default (ABC.java:149) - #0001 was active for 324234 milliseconds and has been removed automaticaly. The Thread responsible was named ‘Thread-1′, but the last SQL it performed is unknown because the trace property is not enabled.
,这是由默认设置:jdbc-0.proxool.maximum-active-time=300000 所决定的,见:http://proxool.sourceforge.net/properties.html
你说的那个 应该是 连接的最长时间: 是这个属性:
jdbc-0.proxool.maximum-connection-lifetime=18000000 Default is 4 hours
给你参考这个 配置:[url]http://proxool.sourceforge.net/properties.html[/url]
以及这个 [url]http://it.oyksoft.com/post/3983/[/url]
max-active-time
其含义是一个线程持有一个连接的最长时间,而不管这个连接是否处于 active 状态, 并且如果线程的持有时间超过这个时间的之后会自动清除掉这个连接,也就是kill掉这个线程,那它刚才占用的那个连接就丢回到连接池里面。缺省为 5 分钟,但是很多时候5分钟并不够用, 所以需要在配置文件中进行设置, 其单位为毫秒(ms).