In my code, I have an executor service running:
//these are global variables
def newXmlParser = new XmlParser()
def processedResponse
Someloop.each{
URL->
executorService.execute(new Runnable() {
public void run() {
someURLService(URL)
}
});
}
where
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)
}
I am trying to implement this, because I have code dependent on the results of all finished tasks of the 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) {
...
}
However, it doesn't wait until it's finished, but bypasses the 'awaitTermination' with an InterruptedException. It doesn't give me any message, localized message, or cause.
Does anybody have a solution to this problem? Let me know if you need more details.