javafx应用程序的性能问题
我正在使用javafx构建一个桌面应用程序,我正在使用ftp下载一个大约500 MB的文件。我正在使用DirectoryChooser选择下载位置,但在选择目录后,我的应用程序将挂起并且没有响应。 虽然文件已下载 这是我的密码:-javafx应用程序的性能问题,java,javafx,javafx-2,Java,Javafx,Javafx 2,我正在使用javafx构建一个桌面应用程序,我正在使用ftp下载一个大约500 MB的文件。我正在使用DirectoryChooser选择下载位置,但在选择目录后,我的应用程序将挂起并且没有响应。 虽然文件已下载 这是我的密码:- try { ftpClient.setFileType(FTP.BINARY_FILE_TYPE); success = ftpClient.changeWorkingDirectory(PATH + preset +
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并发性的文档。
您正在阻止UI的应用程序线程上执行下载。请看一下有关JavaFX并发性的文档。
旁注:使用“资源尝试”可正确关闭流。旁注:使用“资源尝试”可正确关闭流。