-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
}
}
}