/**
* Closes idle connections.
*
* @param idletime the time the connections should have been idle
* in order to be closed now
* @param tunit the unit for the {@code idletime}
*/
@Override
public void closeIdleConnections(final long idletime, final TimeUnit tunit) {
Args.notNull(tunit, "Time unit");
final long t = idletime > 0 ? idletime : 0;
if (log.isDebugEnabled()) {
log.debug("Closing connections idle longer than " + t + " " + tunit);
}
// the latest time for which connections will be closed
final long deadline = System.currentTimeMillis() - tunit.toMillis(t);
poolLock.lock();
try {
final Iterator<BasicPoolEntry> iter = freeConnections.iterator();
while (iter.hasNext()) {
final BasicPoolEntry entry = iter.next();
if (entry.getUpdated() <= deadline) {
if (log.isDebugEnabled()) {
log.debug("Closing connection last used @ " + new Date(entry.getUpdated()));
}
iter.remove();
deleteEntry(entry);
}
}
} finally {
poolLock.unlock();
}
}
ConnPoolByRoute.java 文件源码
java
阅读 25
收藏 0
点赞 0
评论 0
项目:purecloud-iot
作者:
评论列表
文章目录