I am trying to implement multithreading using ExecutorService for downloading files parallely. Below is my code
public void downloadFiles(List<String> filenames, final String fileSavePath) {
if (filenames != null && filenames.size() > 0) {
List<Callable<Void>> jobs = new ArrayList();
for (final String fileName : filenames) {
jobs.add(new Callable() {
public Void call() throws Exception {
downloadFile(fileName, fileSavePath);
return null;
}
});
}
performJobs(jobs);
}
}
My requirement is that i want to return a status from this method after all the files are downloaded succesfully. I am not sure how to do this. I cannot access variable of inner class from an outer one.
Any advice would be appreciable.
Thanks
From the Javadoc of Callable:
Taking a cue from this, change
List<Callable<Void>> jobstoList<Callable<Boolean>> jobsand similarly change your return type of yourcallmethod. Using this, after completion of the task, you can then check the returned status.