1public static class IdleConnectionMonitorThread extends Thread {
2
3 private final HttpClientConnectionManager connMgr;
4 private volatile boolean shutdown;
5
6 public IdleConnectionMonitorThread(HttpClientConnectionManager connMgr) {
7 super();
8 this.connMgr = connMgr;
9 }
10
11 @Override
12 public void run() {
13 try {
14 while (!shutdown) {
15 synchronized (this) {
16 wait(5000);
17 // Close expired connections
18 connMgr.closeExpiredConnections();
19 // Optionally, close connections
20 // that have been idle longer than 30 sec
21 connMgr.closeIdleConnections(30, TimeUnit.SECONDS);
22 }
23 }
24 } catch (InterruptedException ex) {
25 // terminate
26 }
27 }
28
29 public void shutdown() {
30 shutdown = true;
31 synchronized (this) {
32 notifyAll();
33 }
34 }
35
36}
37