com.mashape.unirest.http.async.utils.AsyncIdleConnectionMonitorThread Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of unirest-java Show documentation
Show all versions of unirest-java Show documentation
Simplified, lightweight HTTP client library
package com.mashape.unirest.http.async.utils;
import java.util.concurrent.TimeUnit;
import org.apache.http.impl.nio.conn.PoolingNHttpClientConnectionManager;
public class AsyncIdleConnectionMonitorThread extends Thread {
private final PoolingNHttpClientConnectionManager connMgr;
private volatile boolean shutdown;
public AsyncIdleConnectionMonitorThread(PoolingNHttpClientConnectionManager connMgr) {
super();
this.connMgr = connMgr;
}
@Override
public void run() {
try {
while (!shutdown) {
synchronized (this) {
wait(5000);
// Close expired connections
connMgr.closeExpiredConnections();
// Optionally, close connections
// that have been idle longer than 30 sec
connMgr.closeIdleConnections(30, TimeUnit.SECONDS);
}
}
} catch (InterruptedException ex) {
// terminate
}
}
public void shutdown() {
shutdown = true;
synchronized (this) {
notifyAll();
}
}
}