I have two tasks, one for download and another for unzip;
public class DownloadUtil {
public static void downloadHtml(MainViewController controller, String dns, int port, String offlineUUID, String filePath, Map<String, String> cookies) throws IOException {
String urlHtml = "http://" + dns + ":" + port + Constants.TARGET_SERVICE_DOWNLOADFILES + offlineUUID;
System.out.println(urlHtml);
Executors.newSingleThreadExecutor().execute(new DownloaderTask(controller, urlHtml, filePath, cookies));
}
and
public class UnzipUtil {
public static void unZipIt(String zipFile, String outputFolder) {
Executors.newSingleThreadExecutor().execute(new UnzipTask(zipFile, outputFolder));
}
}
and I call them in my code this way:
DownloadUtil.downloadHtml(this, dns, port, uuid, filePathHtmlDownload, cookies);
UnzipUtil.unZipIt(filePathHtmlDownload, outputFolder);
But the problem is that the Unzip method is calling before the download method finish, how can I do to unZipIt wait for downloadHtml method?
Pass the same
SingleThreadExecutorto both methods. Your tasks are then done sequentially by theExecutor.And your methods now look like: