Example usage for org.apache.http.impl.client ConnectionStatistics getConnectionState

List of usage examples for org.apache.http.impl.client ConnectionStatistics getConnectionState

Introduction

In this page you can find the example usage for org.apache.http.impl.client ConnectionStatistics getConnectionState.

Prototype

public State getConnectionState() 

Source Link

Usage

From source file:org.apache.http.impl.client.AbstractStatisticsGatheringHttpClient.java

/**
 * Creates a new HTTP client.// www .j a v a 2  s.c  o  m
 *
 * @param conman    the connection manager
 * @param params    the parameters
 */
protected AbstractStatisticsGatheringHttpClient(final ClientConnectionManager conman, final HttpParams params) {
    defaultParams = params;
    connManager = conman;
    Thread t = new Thread() {
        @Override
        public void run() {
            while (true) {
                synchronized (connectionStats) {
                    for (Integer key : connectionStats.keySet()) {
                        ConnectionStatistics stats = connectionStats.get(key);
                        if (stats.getConnectionState().equals(ConnectionStatistics.State.OPEN)) {
                            if (System.currentTimeMillis() - stats.getLastUsed() > 30000) {
                                log.warn("Possible connection leak for connection " + key + " duration(ms): "
                                        + (System.currentTimeMillis() - stats.getLastUsed()) + " request: "
                                        + stats.getLastRequest());
                            }
                        }
                    }
                }
                try {
                    Thread.currentThread().sleep(30000);
                } catch (InterruptedException e) {
                }
            }
        }
    };
    t.start();
}