Need advice on starting three threads to run three Windows or Linux commands in parallel

classic Classic list List threaded Threaded
1 message Options
Reply | Threaded
Open this post in threaded view

Need advice on starting three threads to run three Windows or Linux commands in parallel

I'm writing my first test case using TestNG and I'm also new to Java.  I need to spawn three threads to simultaneously execute three different commands (either Windows or Linux; Windows snippet fleshed out below).  The first command runs until it times out.  The second two run to completion.  

I'm using ProcessBuilder to execute the three commands and I have that working if I don't try to do any signalling between the processes.  However, when I create a monitor and then try to wait on it, the test blocks until the first command times out.  Notify doesn't seem to be giving me a problem but I don't really know.  I'm sure I'm doing something wrong but have no idea what it is and can't find anything similar on the internet.  I've stripped the program down to the basics, hopefully without destroying anything, and coded everything inline to eliminate any logic errors (initially had it as a separate executeCommand method like you see in the Linux clause).  This really isn't a TestNG problem but hoped someone in this community has done this in the past.

Rather than waiting for the first command to time out, I want to destroy it once the other two processes have completed

Thanks in advance.

public class SmokeTest {
  public void executeTest() throws IOException, InterruptedException, IllegalMonitorStateException {
 System.out.println("Begin executeTest");
 final Object monitor = new Object();

 String osname = System.getProperty("");
 boolean processComplete = false;

 if (osname.equals("Linux")) {
//  String[] cmd = new String[]{"/bin/sh", "cd mp && ./"};
//  executeCommand(cmd, true, false, false);
 } else {
 String[] cmd = new String[]{"cmd.exe ", "/c cd c:\\mp && runx2.bat "};
 ProcessBuilder pb1 = new ProcessBuilder(cmd);
 Process process1 = pb1.start();
//  synchronized(monitor){
//  while (!processComplete){
//  try { 
//  monitor.wait(); 
//  } catch(InterruptedException e) { 
//  System.out.println("InterruptedException caught"); 
//  } 
//  }
//  }
 cmd = new String[]{"cmd.exe ", "/c cd c:\\mp && runy.bat "};

 ProcessBuilder pb2 = new ProcessBuilder(cmd);
 Process process2 = pb2.start();
 cmd = new String[]{"cmd.exe ", "/c cd c:\\mp && runz.bat "};
 ProcessBuilder pb3 = new ProcessBuilder(cmd);
 Process process3 = pb3.start();
 System.out.println("End executeTest");

You received this message because you are subscribed to the Google Groups "testng-users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to [hidden email].
To post to this group, send email to [hidden email].
Visit this group at
For more options, visit