Win a copy of Mesos in Action this week in the Cloud/Virtualizaton forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

thread /process does not terminate

 
Paul Agola
Greenhorn
Posts: 23
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Sheriff
Posts: 21107
32
Eclipse IDE Firefox Browser MySQL Database
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 13062
6
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 23
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Sheriff
Posts: 21107
32
Eclipse IDE Firefox Browser MySQL Database
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 23
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Sheriff
Posts: 21107
32
Eclipse IDE Firefox Browser MySQL Database
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 23
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 23
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic