【发布时间】:2017-06-08 20:44:46
【问题描述】:
我正在使用AsyncHttpClient,并同时发出许多 http 请求。 我收到以下错误:
java.util.concurrent.RejectedExecutionException: Thread limit exceeded replacing blocked worker
我怎样才能做出一个新请求等待直到有空闲线程的行为?
我的代码:
public class MyClass {
private AsyncHttpClient asyncHttpClient = new DefaultAsyncHttpClient();
public JSONObject jsonFromUrl(String requestUrl) {
CompletableFuture<Response> futureResponse = asyncHttpClient.prepareGet(requestUrl).
addHeader("header-name", "header-value").execute().toCompletableFuture();
try {
Response response = futureResponse.get();
... handling response
} catch (Exception e) {
... handling exception
}
}
}
【问题讨论】:
标签: java http asynchronous asynchttpclient