The Processing.logoutSubscriberByMac(mac) has that code on it:
The problem is that if things are like how are presented above, the servlet does not redirect the page: response.sendRedirect("/page/to/redirect");. Even if the logs are written logger.info("subscriber with mac ..."), the browser tries to redirect, but it gets stuck on redirection and after loading timeout, the browser's failure page appears. If I comment the line that contains command to wait, proc.waitFor();, everything works well.
Question: Can anybody explain me why that behavior? Do you have any suggestions for that scenario?
Note: it seems to me that Process.waitFor() "steals" servlet's OutputStream. But I might be wrong.
Look bellow at my code, modified according to the pointed article, but the servlet still hangs on redirect.
Joined: Nov 26, 2009
William Brogden wrote:You are not correctly handling the Process stderr and stdout streams so Process is hanging - see the JavaDocs for Process and the more complete explanation in the article Muhammad cited.
From Javadocs you can read: Because some native platforms only provide limited buffer size for standard input and output streams, failure to promptly write the input stream or read the output stream of the subprocess may cause the subprocess to block, or even deadlock.
If you look at my post in response to Muhammad Saifuddin, I think it is clear that:
1. My process does not hang as long as the logs are written to files. (I refer to logs that are bellow process.waitFor() call, in servlet doPost(..) method).
2. Taking in account what Javadocs sais : All its standard I/O (i.e. stdin, stdout, stderr) operations will be redirected to the parent process, where they can be accessed via the streams obtained using the methods getOutputStream(), getInputStream(), and getErrorStream(), it seems that closing process's streams you close servlets streams.
If you have some suggestions to guide me, help me please.
Author and all-around good cowpoke
Joined: Mar 22, 2000
it seems that closing process's streams you close servlets streams.
Your code still does not handle the Process streams correctly because you try to do all that in a single Thread. Read the article again, this time, all the way to listing 4.5 which shows how to handle each stream in its own Thread.