简体   繁体   English

Swing应用程序中的Java运行时问题

[英]Java runtime issue from Swing application

I have one swing application from which I am executing one jar file, which will do some processing internally. 我有一个swing应用程序,将从中执行一个jar文件,该文件将在内部进行一些处理。 Process I have is as below: 1. one java file with main() which loads swing GUI. 我的流程如下:1.一个带有main()的Java文件,它加载swing GUI。 From that GUI I can browse and load required jar files to execute. 通过该GUI,我可以浏览并加载所需的jar文件以执行。

public static void main(String[] args)
{
    javax.swing.SwingUtilities.invokeLater(new Runnable() {
        public void run() {
            MigrationProcessElementDialog.createAndShowGUI();

        }
    });

}
  1. From swing application I am loading jar file as: 从秋千应用程序我正在加载jar文件为:

Runtime rt = Runtime.getRuntime();   
// replacePath is the path of the jar file to be loaded.
Process proc = rt.exec("java -jar " + replacePath);   
int exitVal = proc.waitFor();
  1. When I trigger execution, from Task Manager I am seeing, two javaw.exe (one for eclipse, one for SWING GUI) and one java.exe for program flow. 当我触发执行时,从任务管理器中可以看到两个javaw.exe(一个用于Eclipse,一个用于SWING GUI)和一个java.exe用于程序流。 But program flow continues few times (evident from log update) but stuck after certain time. 但是程序流继续运行几次(从日志更新中可以看出),但是在一定时间后停滞了。

  2. As soon as, I kill my swing GUI javaw.exe; 我立刻杀死了我的摇摆GUI javaw.exe; program flow starts and continues rest of the part promptly. 程序流程开始并立即继续其余部分。 So it seems to me that somehow javaw.exe is blocking java.exe execution. 因此在我看来,javaw.exe某种程度上阻止了java.exe的执行。 Is it at all possible? 有可能吗? what's the resolution of it? 它的分辨率是多少?

If I execute, my process executable jar from command prompt using normal java -jar "path" command, program flow is not stuck, it's working as expected. 如果执行,则使用普通的java -jar“ path”命令从命令提示符处执行我的进程可执行jar,程序流未卡住,运行正常。

Only facing the problem when I am executing from GUI or using Runtime. 仅当我从GUI执行或使用运行时时才遇到问题。 I used ProcessBuilder also; 我还使用了ProcessBuilder。 but faced same problem. 但面临同样的问题。

If any one can please give me any clue it will be really helpful. 如果有人可以给我任何线索,那将非常有帮助。 Thanks! 谢谢!

You should handle output of process (both of stdout, stderr ). 您应该处理进程的输出(stdout和stderr两者)。 Because, these outputs will be redirected to the parent process through three streams (getOutputStream(), getInputStream(), getErrorStream() ). 因为,这些输出将通过三个流(getOutputStream(),getInputStream(),getErrorStream())重定向到父进程。 If not handled, it will block when child process produces output. 如果不处理,它将在子进程产生输出时阻塞。

Process documentation 工艺文件

Some native platforms only provide limited buffer size for standard input and output streams, failure to promptly write the input stream or read the output stream of the subprocess may cause the subprocess to block, and even deadlock. 一些本机平台仅为标准输入和输出流提供有限的缓冲区大小,未能及时写入子流程的输入流或读取子流程的输出流可能导致子流程阻塞,甚至死锁。

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

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM