gpt4 book ai didi

java - 我该如何做才能让方法等待执行器运行?

转载 作者:太空宇宙 更新时间:2023-11-04 07:49:16 24 4
gpt4 key购买 nike

我有一个执行程序在单个ThreadExecutor中运行,我需要在它完成后调用其他方法(saveJsonFile()),但仅当我的执行程序完成时

我与执行者的类(class)

        ExecutorService e = Executors.newSingleThreadExecutor();

//Download HTML and Unzip Threads
typeDownloaded = "html";
DownloadUtil.downloadHtml(e, this, dns, port, offlineUuid, filePathHtmlDownload, cookies, typeDownloaded);
UnzipUtil.unZipHtml(e, this, filePathHtmlDownload, outputFolder, typeDownloaded);
e.shutdown();
saveJsonFile();

我的 UnzipUtil 类:

public class UnzipUtil {

public static void unZipHtml(Executor e, MainViewController controller, String zipFile, String outputFolder, String type) {
e.execute(new UnzipTask(controller, zipFile, outputFolder, type));
}

public static void unZipImages(Executor e, MainViewController controller, int numImg, String outputFolder, String type) throws SystemException, PortalException {
String filePath;

filePath = System.getProperty("user.home") + File.separator + "Documents" + File.separator + "TargetApp" + File.separator + "TempImageDownload.zip";
System.out.println(filePath);
e.execute(new UnzipTask(controller, filePath, outputFolder, type));

}
}

最佳答案

也许我没有明白这个问题,但是你不能使用 Futures and Callables ?基本上,您可以指定一个“回调”,当您的解压缩任务完成时将调用该“回调”...引用链接(您还可以在其中找到有关如何使用机器的简单示例):

A Future represents the result of an asynchronous computation. Methods are provided to check if the computation is complete, to wait for its completion, and to retrieve the result of the computation.

关于java - 我该如何做才能让方法等待执行器运行?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/14761084/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com