This week's book giveaways are in the Java EE and JavaScript forums.
We're giving away four copies each of The Java EE 7 Tutorial Volume 1 or Volume 2(winners choice) and jQuery UI in Action and have the authors on-line!
See this thread and this one for details.
The moose likes Threads and Synchronization and the fly likes process has not exited Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of The Java EE 7 Tutorial Volume 1 or Volume 2 this week in the Java EE forum
or jQuery UI in Action in the JavaScript forum!
JavaRanch » Java Forums » Java » Threads and Synchronization
Bookmark "process has not exited" Watch "process has not exited" New topic
Author

process has not exited

Madhu Bala
Greenhorn

Joined: Jul 30, 2002
Posts: 8
Hi Friends,

I am using Runtime class in my application.It creates JAR & EAR Files.For that I used Runtime class.
Here my peace of code Pls help me what is worng in this code.


try {
String stmt = "jar -Mcvf " + ejbJarName + " META-INF/MANIFEST.MF " +" META-INF/ejb-jar.xml " + " com";
Process stmtProcess = java.lang.Runtime.getRuntime().exec(stmt);
if (osname.startsWith("Windows")) {
System.out.println("use Thread.sleep(" + ntdepltime + ")");
Thread.sleep(100000);
try
{
stmtProcess.exitValue();
}catch(IllegalThreadStateException exp){ System.out.println("Madhu exception "+exp); }
} else {
System.out.println("use waitFor()");
stmtProcess.waitFor();
}
stmt = "jar -Mcvf " + newEarName + " META-INF/MANIFEST.MF " +" META-INF/application.xml " + ejbJarName + " " + clientJarName;
stmtProcess = java.lang.Runtime.getRuntime().exec(stmt);
if (osname.startsWith("Windows")) {
System.out.println("use Thread.sleep(" + ntdepltime + ")");
Thread.sleep(100000);
} else {
System.out.println("use waitFor()");
stmtProcess.waitFor();
}
} catch (Exception e) {
e.printStackTrace();
}

After JAR file creatation execution it is throwing java.lang.IllegalThreadStateException exception.

Pls help me in this regard.

thanks,
Madhu


madhu babu
Stan James
(instanceof Sidekick)
Ranch Hand

Joined: Jan 29, 2003
Posts: 8791
Put your sleep in a synchronized block as shown in THIS thread.

I'm curious why you don't trust waitFor in Windows. Are there known issues with that?

You might also search this thread for StreamGobbler. There were some good examples of reading stdout and errout from the process. I only did all this stuff once and I waited for the outputs to end rather than using waitFor(). The streams seemed to run a while after waitFor returned, maybe because they were buffered or something.


A good question is never answered. It is not a bolt to be tightened into place but a seed to be planted and to bear more seed toward the hope of greening the landscape of the idea. John Ciardi
 
 
subject: process has not exited