Example usage for org.apache.http.impl.conn.tsccm BasicPoolEntry getUpdated

List of usage examples for org.apache.http.impl.conn.tsccm BasicPoolEntry getUpdated

Introduction

In this page you can find the example usage for org.apache.http.impl.conn.tsccm BasicPoolEntry getUpdated.

Prototype

public long getUpdated() 

Source Link

Usage

From source file:org.apache.http.impl.conn.tsccm.ConnPoolByRoute.java

/**
 * Closes idle connections.//  w  w w  .  j  a  va 2  s. co  m
 *
 * @param idletime  the time the connections should have been idle
 *                  in order to be closed now
 * @param tunit     the unit for the <code>idletime</code>
 */
@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();
    }
}