简体   繁体   English

当我通过Java应用程序中的进程运行pg_restore时,应用程序冻结

[英]When I run pg_restore via process in java application, application freeze

When I run pg_restore via process in java application, application freeze and info message don't show, but process successfully finished. 当我通过Java应用程序中的进程运行pg_restore ,应用程序冻结和信息消息未显示,但进程成功完成。 Why it so? 为什么会这样呢? I use PostgreSQL 9.2. 我使用PostgreSQL 9.2。

Method's code: 方法的代码:

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();
    }
}

}

Don't block the EDT (Event Dispatch Thread) - the GUI will 'freeze' when that happens. 不要阻止EDT(事件调度线程)-发生这种情况时,GUI将“冻结”。 Instead of calling Thread.sleep(n) implement a Swing Timer for repeating tasks or a SwingWorker for long running tasks. 而不是调用Thread.sleep(n)实现用于重复任务的Swing Timer或用于长时间运行的任务的SwingWorker See Concurrency in Swing for more details. 有关更多详细信息,请参见Swing中的并发

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 如果 pg_restore 正在进行,我们会在应用程序中遇到任何运行时问题吗? - Will we face any runtime issue in application if pg_restore is in progress? 通过ssh将Java应用程序作为后台进程运行 - Run java application as background process via ssh 当我在安装过程中执行我的应用程序时,izPack会冻结 - izPack freeze when i execute my application in installation process Java进程waitFor()函数导致应用程序冻结 - Java process waitFor() function causes application to freeze 将Java应用程序作为后台进程运行 - run java application as background process Java-如何使我的应用程序长期稳定运行,以免打h,冻结? - Java - How can i make my application long run stable so that it does not hiccups, freeze? 如何让 java 运行应用程序,当用户关闭应用程序时,java 在 mac 或 windows 中运行另一个进程 - how to get java to run an application and when user closes the application, java runs another process in mac or windows 我可以通过Web Start使用Java 6运行JavaFX应用程序吗? - Can I run a JavaFX application via Web Start with Java 6? 使用 java Runtime() 或 Process Builder 执行或运行应用程序 - Execute or Run application with java Runtime() or Process Builder 如何在Java中以后台运行应用程序(进程) - How to run an application(process) in java as background
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM