在我的代码中,我有一个运行执行器服务:
//these are global variables
def newXmlParser = new XmlParser()
def processedResponse
Someloop.each{
URL->
executorService.execute(new Runnable() {
public void run() {
someURLService(URL)
}
});
}
,其中
public void someURLService(URL){
def urlConnection = HttpURLConnection(URL)
def response = urlConnection.getInputStream()
parseResponse(response)
}
public synchronized void parseResponse(response){
//previously declared XmlParser
processedResponse = newXmlParser.parse(response)
}
我正在尝试实现这一点,因为我的代码依赖于ExecutorService的所有已完成任务的结果:
How to wait for all threads to finish, using ExecutorService?
Someloop.each{
URL->
executorService.execute(new Runnable() {
public void run() {
someURLService(URL)
}
});
}
executorService.shutdown();
try {
executorService.awaitTermination(Long.MAX_VALUE, TimeUnit.NANOSECONDS);
} catch (InterruptedException e) {
...
}
然而,它不会等到它完成,而是用InterruptedException绕过'awaitTermination'。它不会给我任何消息,本地化消息或原因。
有没有人能解决这个问题?如果您需要更多详细信息,请与我们联系。