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 就是一个后台线程 定期检查连接的健康状况。