-1
我使用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
}
}
}