当我在java应用程序中通过进程运行pg_restore时,应用程序冻结
当我在java应用程序中通过进程运行当我在java应用程序中通过进程运行pg_restore时,应用程序冻结,java,swing,postgresql,Java,Swing,Postgresql,当我在java应用程序中通过进程运行pg_restore时,应用程序冻结和信息消息不会显示,但进程已成功完成。为什么会这样?我使用PostgreSQL 9.2 方法代码: private void restoreDB() { JFileChooser fileopen = new JFileChooser(); FileNameExtensionFilter filter = new FileNameExtensionFilter("DB FILES", "sql");
pg_restore
时,应用程序冻结和信息消息不会显示,但进程已成功完成。为什么会这样?我使用PostgreSQL 9.2
方法代码:
private void restoreDB() {
JFileChooser fileopen = new JFileChooser();
FileNameExtensionFilter filter = new FileNameExtensionFilter("DB FILES", "sql");
fileopen.addChoosableFileFilter(filter);
fileopen.setCurrentDirectory(new java.io.File("C:/backups/"));
fileopen.setDialogTitle("Выберите папку для резервной копии");
fileopen.setFileSelectionMode(JFileChooser.FILES_AND_DIRECTORIES);
fileopen.setAcceptAllFileFilterUsed(false);
int ret = fileopen.showDialog(null, "Restore DB");
if (ret == JFileChooser.APPROVE_OPTION) {
File file = fileopen.getSelectedFile();
try {
String path = file.getAbsolutePath();
System.out.println(path);
String user = "postgres";
String dbName = "Auto";
String executeCmd = "pg_restore -i -U " + user + " -d " + dbName+" -v "+ path;
Process runtimeProcess;
runtimeProcess = Runtime.getRuntime().exec(executeCmd);
int processComplete = runtimeProcess.waitFor();
if (processComplete == 0) {
javax.swing.JOptionPane.showMessageDialog(null, "Successfull!");
log.info("Successfull!");
} else {
javax.swing.JOptionPane.showMessageDialog(null, "Unsuccessfully");
log.info("Unsuccessfully");
}
}catch (Exception ex) {
ex.printStackTrace();
}
}
}
不要阻止EDT(事件调度线程)-发生这种情况时,GUI将“冻结”。不要调用
Thread.sleep(n)
为重复任务执行Swing计时器,或为长时间运行的任务执行SwingWorker
。有关更多详细信息,请参阅。不要阻止EDT(事件调度线程)-发生这种情况时,GUI将“冻结”。不要调用Thread.sleep(n)
为重复任务执行Swing计时器,或为长时间运行的任务执行SwingWorker
。有关更多详细信息,请参阅。不要阻止EDT(事件调度线程)-发生这种情况时,GUI将“冻结”。不要调用Thread.sleep(n)
为重复任务执行Swing计时器,或为长时间运行的任务执行SwingWorker
。有关更多详细信息,请参阅。不要阻止EDT(事件调度线程)-发生这种情况时,GUI将“冻结”。不要调用Thread.sleep(n)
为重复任务执行Swing计时器,或为长时间运行的任务执行SwingWorker
。有关更多详细信息,请参阅。@andrewhompson,这需要一个答案。我在“感谢您的答案”中找到了答案!进程的输出有问题。“否则,进程将填充其输出缓冲区,并停止等待,直到您通过读取输出清空缓冲区。”@AndrewThompson这需要是一个答案我在中找到了答案,感谢您的回答!进程的输出有问题。“否则,进程将填充其输出缓冲区,并停止等待,直到您通过读取输出清空缓冲区。”@AndrewThompson这需要是一个答案我在中找到了答案,感谢您的回答!进程的输出有问题。“否则,进程将填充其输出缓冲区,并停止等待,直到您通过读取输出清空缓冲区。”@AndrewThompson这需要是一个答案我在中找到了答案,感谢您的回答!进程的输出有问题。“否则,进程将填充其输出缓冲区,并停止等待,直到您通过读取输出清空缓冲区。”