gpt4 book ai didi

java - javafx 应用程序的性能问题

转载 作者:行者123 更新时间:2023-12-01 21:49:29 26 4
gpt4 key购买 nike

我正在使用 javafx 构建桌面应用程序,我正在使用 ftp 下载大约 500 MB 的文件。我正在使用 DirectoryChooser 选择下载位置,但选择目录后我的应用程序挂起并且没有响应。虽然文件已下载。

这是我的代码:-

try {
ftpClient.setFileType(FTP.BINARY_FILE_TYPE);
success = ftpClient.changeWorkingDirectory(PATH + preset + "/" + file_to_download + offset);
System.out.println("Download Path:-" + PATH + preset + "/" + file_to_download + offset);
if (!success) {
System.out.println("Could not changed the directory to RIBS");
return;
} else {
System.out.println("Directory changed to RIBS");
}
FTPFile[] files = ftpClient.listFiles();
for (FTPFile file : files) {
if (file.getName().contains(".zip")) {
dfile = file.getName();
}

}
DirectoryChooser dirChooser = new DirectoryChooser();
File chosenDir = dirChooser.showDialog(tableView.getScene().getWindow());
System.out.println(chosenDir.getAbsolutePath());
OutputStream output;
output = new FileOutputStream(chosenDir.getAbsolutePath() + "/" + dfile);
int timeOut = 500;
ftpClient.setConnectTimeout(timeOut);
if (ftpClient.retrieveFile(dfile, output) == true) {
downloadButton.setDisable(true);
}
output.close();

} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}

我该如何改进?

最佳答案

您正在应用程序线程上执行下载,这会阻止 UI。查看有关 JavaFX 并发性的文档。 https://docs.oracle.com/javase/8/javafx/interoperability-tutorial/concurrency.htm

关于java - javafx 应用程序的性能问题,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/35389881/

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