简体   繁体   English

通过JButton动作侦听器并行运行的Perl脚本的多个实例

[英]Multiple instances of perl script running in parallel via JButton action listener

I'm executing a Perl script via "Runtime.getRuntime().exec("perl C:/script.pl")" 我正在通过"Runtime.getRuntime().exec("perl C:/script.pl")"执行Perl脚本

as part of a Jbutton action listener. 作为Jbutton动作侦听器的一部分。 I would like to be able to click the button twice and get two instances of the same Perl script running. 我希望能够单击两次按钮,并使同一Perl脚本的两个实例运行。 The script is reading in a text file so it acts a little differently depending on the text file the second time it is started but in general the script does the same thing. 该脚本正在读取文本文件,因此第二次启动时,该操作取决于文本文件,但通常情况下,该脚本执行相同的操作。

I've tried to combat this by wrapping the runtime command in a new thread and executing a ".run()" on it each time the button is pressed but this only seems to interrupt the first instance and start the new one. 我试图通过将运行时命令包装在新线程中并在每次按下按钮时在其上执行".run()"来解决此问题,但这似乎只会中断第一个实例并启动新实例。 There seems to be no way to execute two of the same Perl script in parallel. 似乎没有办法并行执行两个相同的Perl脚本。 Any ideas on how I can accomplish this? 关于如何实现此目标的任何想法?

ActionListener edit = new ActionListener() {

   public void actionPerformed(ActionEvent actionEvent) {

      class GetThread implements Runnable {

        public void run() {
          try {
            Runtime.getRuntime().exec("C:/Perl/bin/perl5.16.3.exe C:/Perl/get.pl", null, new File("C:/Perl"));
          } catch (IOException e1) {
            exceptionLog(e1);
          }
        }
      }
   GetThread get = new GetThread();
   get.run();
   }
}

http://docs.oracle.com/javase/7/docs/api/java/lang/Runtime.html says http://docs.oracle.com/javase/7/docs/api/java/lang/Runtime.html

Every Java application has a single instance of class Runtime that allows the application to interface with the environment in which the application is running. 每个Java应用程序都有一个单独的Runtime类实例,该实例允许该应用程序与应用程序运行所在的环境进行交互。 The current runtime can be obtained from the getRuntime method. 当前的运行时可以从getRuntime方法获得。

It may be blocking on your call. 它可能会阻止您的通话。

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

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