aspose file tools*
The moose likes Threads and Synchronization and the fly likes thread /process does not terminate Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Threads and Synchronization
Bookmark "thread /process does not terminate" Watch "thread /process does not terminate" New topic
Author

thread /process does not terminate

Paul Agola
Greenhorn

Joined: Jul 03, 2012
Posts: 23
have a java GUI that when a menu item is clicked it will use the runtime.exec method to execute a process and bring up a report. It does that just fine but then it suddenly freezes up and i cannot access anything for a while. I cannot even scroll through the report to analyse the data. The report is shown on an xterm and i am wondering why i cannot do anything after the report is created. 1. My java code that executes the csh script


When i comment out my error checking code everything works fine and the program doesn't freeze up. It has something to do with the inputsream reading an erro message. This is the portion of code that i comment out



it is somehow hanging up when this happens and i dont know why. Can somebody help because i definately need this error checking portion incase anything goes wrong. I have narrowed it down to the while loop. Everything else works normally but as soon as i put the while loop to read from the buffer it freezes up again. Somehow the subprocess is taking too long to temrinate. Here is the code that is not working


Essentially there are no errors in the script because it produces the report so the geterrorstream should be NULL causing the while loop to be ignored but it is not? It seems like it is reading something for a while(hence freezes up).

Paul Clapham
Bartender

Joined: Oct 14, 2005
Posts: 18570
    
    8

You need to read the classic article When Runtime.exec() won't and implement its recommendations.
William Brogden
Author and all-around good cowpoke
Rancher

Joined: Mar 22, 2000
Posts: 12785
    
    5
Hanging while exec-ing is frequently due to not consuming both the stdout and stderr streams.

You can not depend on consuming both unless you start a separate Thread to consume each one. Slight differences in program output can cause irregular behaviour.

Bill
Paul Agola
Greenhorn

Joined: Jul 03, 2012
Posts: 23
William Brogden wrote:Hanging while exec-ing is frequently due to not consuming both the stdout and stderr streams.

You can not depend on consuming both unless you start a separate Thread to consume each one. Slight differences in program output can cause irregular behaviour.

Bill


Sir
i am a novice at java threading and i do not understand what you mean
Paul Clapham
Bartender

Joined: Oct 14, 2005
Posts: 18570
    
    8

Paul Agola wrote:i am a novice at java threading and i do not understand what you mean


Read the article I posted the link to. You won't have to be a threading genius to understand it. Just read it.
Paul Agola
Greenhorn

Joined: Jul 03, 2012
Posts: 23
Paul Clapham wrote:
Paul Agola wrote:i am a novice at java threading and i do not understand what you mean


Read the article I posted the link to. You won't have to be a threading genius to understand it. Just read it.



i have read the article and i only understand upto page 3. I dont understand how i am supposed to handle both the input and the ouytput with different threads
Paul Clapham
Bartender

Joined: Oct 14, 2005
Posts: 18570
    
    8

Paul Agola wrote:i have read the article and i only understand upto page 3. I dont understand how i am supposed to handle both the input and the ouytput with different threads


Page 4 has an example of exactly that. Read the article and keep reading it (and trying simple code based on it) until you do understand it.
Paul Agola
Greenhorn

Joined: Jul 03, 2012
Posts: 23
Paul Clapham wrote:
Paul Agola wrote:i have read the article and i only understand upto page 3. I dont understand how i am supposed to handle both the input and the ouytput with different threads


Page 4 has an example of exactly that. Read the article and keep reading it (and trying simple code based on it) until you do understand it.


Knowing that this is going to the stderr stream, you can easily write a program to exhaust that stream before waiting for the process to exit.


i am already doing this is in my code and he says this is the solution to the hanging of runtime.exec(). Do you know what he means by "going to the srderr stream? i thought that stream is only for errors that occur when you are trying to execute the command. Right now there is no error and it brings up the xterm and displays the file as expected but it just hangs up
Paul Agola
Greenhorn

Joined: Jul 03, 2012
Posts: 23
Paul Clapham wrote:
Paul Agola wrote:i have read the article and i only understand upto page 3. I dont understand how i am supposed to handle both the input and the ouytput with different threads


Page 4 has an example of exactly that. Read the article and keep reading it (and trying simple code based on it) until you do understand it.



Thus, to circumvent the second pitfall -- hanging forever in Runtime.exec() -- if the program you launch produces output or expects input, ensure that you process the input and output streams.



my program produces output but it is displayed on the xterm so why should i process this output. it calls a csh script that cat information from a log to a file so why should i process it
 
With a little knowledge, a cast iron skillet is non-stick and lasts a lifetime.
 
subject: thread /process does not terminate