我正在使用自己的 ThreadPoolExecutor 来了解我的所有任务何时完成。我有一个方法是 client.get() 调用,如果成功,它会做更多的 client.get() 调用。但是,java.util.concurrent.RejectedExecutionException: Task java.util.concurrent.FutureTask@414ca470 rejected from java.util.concurrent.ThreadPoolExecutor@414ab1a0[Terminated, pool size = 0, active threads = 0, queued tasks = 0, completed tasks = 1]
当我从我的第一次成功中调用 client.get() 时,我得到了。我该如何解决这个错误?
AsyncHttpClient client = new AsyncHttpClient();
int limit = 20;
BlockingQueue<Runnable> q = new ArrayBlockingQueue<Runnable>(limit);
ThreadPoolExecutor executor =
new ThreadPoolExecutor(limit, limit, 20, TimeUnit.SECONDS, q);
client.setThreadPool(executor);
parseSilo(url, context); // this fires client.get() ... as it encounters urls in JSON feed
executor.shutdown();
while (!executor.awaitTermination(10, TimeUnit.SECONDS)) {
Log.e(TAG, executor.getTaskCount() + " tasks left");
}
if (executor.isShutdown()) {
Log.e(TAG, "done");
}
parseSilo 方法
public static void parseSilo(String url, final Context context) {
client.get(url, new AsyncHttpResponseHandler() {
@Override
public void onSuccess(String content) {
Log.i(TAG, "Parsing Silo");
JsonNode rootNode;
//json parsing
// parse collections
for (Show show : listOfShows) {
parseCollections(show.getCollectionUrl()); // another client.get()
}
}
});
}