Im doing library in java, library is for calling external service API. For this I am using AsyncHttpClient
Some part of code:
public CompletableFuture<Optional<TokensResponse>> clientCredentialsGrant(String clientId, String clientSecret, String deviceId, Optional<String> scope) {
AsyncHttpClient asyncHttpClient = asyncHttpClient();
BoundRequestBuilder requestBuilder = asyncHttpClient
.preparePost(host + "/oauth2/token")
.addFormParam("grant_type", "client_credentials")
.addFormParam("device_id", deviceId)
.addFormParam("client_id", clientId)
.addFormParam("client_secret", clientSecret);
if (scope.isPresent()) {
requestBuilder.addFormParam("scope", scope.get());
}
return runRequestWithTokenResponse(requestBuilder, asyncHttpClient);
}
and if some project which is using this lib I will run for example 1000 requests even if they will finish I end up with a lot of threads hanged. After reach request I am doing:
asyncHttpClient.close();
Can I define some thread pool to be used ?
Typically, AHC will usually underperform if you create a new client for each request, as it will create new threads and connection pools for each
This is what I am actually doing..