This week's giveaway is in the Java/Jakarta EE forum. We're giving away four copies of Java EE 8 High Performance and have Romain Manni-Bucau on-line! See thread to stop for that connection. The end result is that I'm left with a zombie process on my unix system.
Does anybody have a work around for this? I don't think it's restricted to just servlets; I think I encountered this in old CGI days as well.
Sometime back I had come across a similar requirement to execute a unix script via servlet and implementation was along the folowing lines. ================================ runObj = Runtime.getRuntime(); proc = runObj.exec(unixscript.sh); int exitcode = proc.waitFor(); ================================
If I understand it correctly the stop applied on the browser will only terminate the browsers ability to display the response from the servlet. while the servlet thread spawned will continue it execution in the container.
Is the zombie process created due to something going wrong in the interaction between the servlet and the unix executable?
Is that really what happens when the user hits "stop"? I only know the little web server I wrote, and it gets no signal from the browser that anything has happened. Instead it gets an IO exception when it tries to write the response because the socket has been terminated by the client.
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
Originally posted by Stan James: Instead it gets an IO exception when it tries to write the response because the socket has been terminated by the client.
Yep, that's all, and so really it's got everything to do with those zombie processes. Make sure you call waitFor() in a finally block, with the corresponding "try" encompassing any attempts to write output back to the browser; that way the process will be reaped even if the service method is aborted. Really just standard good programming practice -- no "trick" involved.