-
Bug
-
Resolution: Duplicate
-
P3
-
None
-
1.0.2
-
sparc
-
solaris_2.5.1
Name: rlT66838 Date: 08/07/97
The Processes don't recognize their parents object :
I have a program creating two different objects with two differents threads
each of these objects use the Process class to run a command on the system.
I use the waitFor method to wait until the process is finished.
Because a use two different thread , my two objects will use the waitFor method at the same time.
When one process will finish , the waitFOr for my first object might receive the Event ,
even if this process was linked to my second object.
Program Test :
_________________________________________________________________________________________________
import java.awt.*;
import java.lang.Object;
import java.io.*;
public class stub {
public static void main(String args[]) {
System.out.println("** Output");
Test test1 = new Test("/bin/sleep 10");
Test test2 = new Test("/bin/sleep 4");
Thread test1Thread = new Thread(test1);
Thread test2Thread = new Thread(test2);
test1Thread.start();
test2Thread.start();
}
}
class Test implements Runnable {
private Process child;
private String cammond1 = "";
public Test(String command) {
command1 = command;
}
public void run() {
Runtime rt = Runtime.getRuntime();
try {
Sytem.out.println(command1 + " will be executed.");
child = rt.exec(command1);
try {
child.waitFor();
}catch (InterruptedException e){
System.out.println(command1 + "Exception error " + e);
}
} catch (java.io.IOException e) {
System.out.println("IO error " + e);
}
System.out.println(command1 + " has been executed.");
}
}
______________________________________________________________________________________
when we run this program on a solaris 5.4 , we have
the result has following ( t is the time ) :
t : **Output
t : /bin/sleep 10 will be executed
t : /bin/sleep 4 will be exectuted
t+4 : /bin/sleep 10 has been executed
t+10 : /bin/sleep 4 has been executed
We try as well on windows 95 ,
the command for test1 was :
ping -n 10 idadress
the command for test2 was :
ping -n 4 idadress
The result is not better.
We need to be able to have more than one waitFor active at the same time,
our project can't work without this feature.
company - Oracle , email - ###@###.###
======================================================================
- duplicates
-
JDK-4034808 Runtime exec sometimes returns wrong value from waitFor()
- Closed