Last active
March 14, 2017 10:00
-
-
Save liry/4eedf3dbfc82475fa9e078c9d7c7bc60 to your computer and use it in GitHub Desktop.
Test runtime change of maxTotal property of HttpClient's ConnectionManager -> it's working ;)
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
final PoolingHttpClientConnectionManager connectionManager = new PoolingHttpClientConnectionManager(); | |
connectionManager.setMaxTotal(1); | |
final CloseableHttpClient httpClient = HttpClientBuilder.create() | |
.setConnectionManager(connectionManager) | |
.build(); | |
final HttpGet get = new HttpGet("http://www.google.com"); | |
final StopWatch stopWatch1 = new StopWatch(); | |
stopWatch1.start(); | |
IntStream.range(0, 10).parallel().forEach(i -> { | |
try { | |
httpClient.execute(get, response -> { | |
try { | |
Thread.sleep(1000); | |
} catch (InterruptedException e) { | |
e.printStackTrace(); | |
} | |
return null; | |
}); | |
} catch (IOException e) { | |
e.printStackTrace(); | |
} | |
}); | |
stopWatch1.stop(); | |
connectionManager.setMaxTotal(10); | |
final StopWatch stopWatch2 = new StopWatch(); | |
stopWatch2.start(); | |
IntStream.range(0, 10).parallel().forEach(i -> { | |
try { | |
httpClient.execute(get, response -> { | |
try { | |
Thread.sleep(1000); | |
} catch (InterruptedException e) { | |
e.printStackTrace(); | |
} | |
return null; | |
}); | |
} catch (IOException e) { | |
e.printStackTrace(); | |
} | |
}); | |
stopWatch2.stop(); | |
System.out.println("before: " + stopWatch1.getTime() + ", after: " + stopWatch2.getTime()); | |
// before: 11888, after: 5802 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment