Example usage for org.apache.http.impl.conn.tsccm ThreadSafeClientConnManager shutdown

List of usage examples for org.apache.http.impl.conn.tsccm ThreadSafeClientConnManager shutdown

Introduction

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

Prototype

public void shutdown() 

Source Link

Usage

From source file:com.baidu.oped.apm.profiler.errorTest.ConcurrentCall.java

@Test
public void test() throws IOException, InterruptedException {
    ((ThreadPoolExecutor) executorService).prestartAllCoreThreads();

    ThreadSafeClientConnManager cm = new ThreadSafeClientConnManager();
    cm.setMaxTotal(200);/*w w  w  .  jav a  2  s .  c  o  m*/
    cm.setDefaultMaxPerRoute(200);

    final HttpClient client = new DefaultHttpClient(cm);
    int call = 400;
    final CountDownLatch latch = new CountDownLatch(call);
    for (int i = 0; i < call; i++) {
        executorService.execute(new Runnable() {
            @Override
            public void run() {
                try {
                    String url = getUrl();
                    logger.info("execute {}", url);
                    final HttpGet httpGet = new HttpGet(url);
                    final HttpResponse execute = client.execute(httpGet);
                    execute.getEntity().getContent().close();

                } catch (ClientProtocolException e) {
                    e.printStackTrace(); //To change body of catch statement use File | Settings | File Templates.
                } catch (IOException e) {
                    e.printStackTrace(); //To change body of catch statement use File | Settings | File Templates.
                } finally {
                    latch.countDown();
                }
            }
        });
    }
    latch.await();
    executorService.shutdown();
    cm.shutdown();

}