I am a new man in the world of threading, now I am trying to solve this problem for a week.
The method running in the thread class is not being called for any reason, I do not know why (but would like to know)
ProcessBuilder processBuilder = new ProcessBuilder ( ); Processbuilder.command ("/ bin / sh", "-c", "echo", w30000001z, none, 16488, 181075 \ nw30000001z, none, 16488, 181082 \ n \ "home / bee / bin / exec / Tablesize "); Process process = process builder. Start (); Process.waitFor (); InputStream stdin = process.getInputStream (); OutputStream stdout = process.getOutputStream (); InputStream stderr = process.getErrorStream (); BufferedReader Reader = New BufferedReader (New InputStreamReader (stdin)); Bufferdreamer Error = New buffed reader (neweststream reader (CDRR)); Stream Gobletler error stream = new streambobbler (process.getErrorStream (), "error"); Streamgb output stream = new streambobbler (process.getInputStream (), "output"); ErrorStream.start (); OutputStream.start (); ErrorStream.join (); OutputStream.join (); TableSize is a dragon executable which takes input through its stdin, processes it and outputs some rows of text. I need to gather this output and do some more processing for it. There is a separate thread for processing output on the inputstream and error stream. This thread has been shown below the square.
/ * Stream Gobbler. Java * / Import java.io.buffferedReader; Import java.io.IOException; Import java.io.InputStream; Import java.io.InputStreamReader; Import java.io.OutputStream; Import java.io.printWriter; Class StreamGobbler Thread is Extended {InputStream; String type; OutputStream OS; Stream gabbler (inputstream, string type) {This (type, type, is empty); } StreamGobbler (InputStream, string type, outputstream redirect) {this.is =; This.Type = type; This.os = redirect; } Public run zero () {{PrintWriter pw = null; If (os! = Null) pw = new printer (OS); System.out.println ("Ajay" + type); InputStreamReader isr = New InputStreamReader (is); Buffed reader br = new buffed reader (ISR); String line = null; While ((line = br.readline ()) = null) {if (pw! = Null) pw.println (line); System.out.println (type + "& gt;" + line); } If (pw! = Null) pw.flush (); } Hold (IOException ioe) {io.printStackTrace (); }}} For some reason, the run method in the StreamGobbler class is not being called. However the Constructor of this class is being executed.
Any help would be greatly appreciated.
You need to call before the radio gobbles , you Process.waitFor () . The stream gobbleables read output to external processes and leave / error streams so that the external process can not be blocked while trying to write but the way you have it, this process tilt the output Writing (and exiting) will have to end.
Result - Deadlock ... if the external process writes too much for its output streams.
Actually, I think the primary problem is that your java code does not write anything on the input stream . Therefore, the external process just waits for input that never comes ... and process.Whatfore () Deadlock waits for the external process. The correct order of things should be:
- To make the process and start it.
- Make gobblers and start them.
- Open the input stream.
- Write content in the input stream.
- Turn off the input stream.
-
- Li>
Comments
Post a Comment