I am writing a program where I am collecting data via a Runtime function as in:
rt = Runtime.getRuntime(); String cmd; cmd = " vmstat 1 2 "; do { try { proc = rt.exec(cmd); in = new BufferedReader(new InputStreamReader(proc.getInputStream())); while ((fromUser = in.readLine()) != null) { try { out.println(hostname +" vmstat " + "Y_ "+fromUser + " _Z " + now()); fromRuser = rin.readLine(); // Ack from server } catch (SocketException e) { e.printStackTrace(); System.err.println("Server host socket disconnect --"); } } out.println("Y_CC "+hostname+" End VMSTAT _Z " + now()); // int exitVal = proc.waitFor(); System.out.println("Process -vmstat- exitValue: " + exitVal); } catch (Throwable t){ t.printStackTrace(); } }while (true); .....
This isn't the entire program but it seems to run fine, for several iterations then hangs, after which I can do a kill -QUIT nnnn and obtain a dump file that looks like
java.lang.Thread.State: RUNNABLE at java.net.SocketOutputStream.socketWrite0(Native Method) at java.net.SocketOutputStream.socketWrite(SocketOutputStream.java:92) at java.net.SocketOutputStream.write(SocketOutputStream.java:136) at sun.nio.cs.StreamEncoder.writeBytes(StreamEncoder.java:202) at sun.nio.cs.StreamEncoder.implFlushBuffer(StreamEncoder.java:272) at sun.nio.cs.StreamEncoder.implFlush(StreamEncoder.java:276) at sun.nio.cs.StreamEncoder.flush(StreamEncoder.java:122) - locked <0xc95640b8> (a java.io.OutputStreamWriter) at java.io.OutputStreamWriter.flush(OutputStreamWriter.java:212) at java.io.BufferedWriter.flush(BufferedWriter.java:236) - locked <0xc95640b8> (a java.io.OutputStreamWriter) at java.io.PrintWriter.newLine(PrintWriter.java:438) - locked <0xc9553ae0> (a java.io.BufferedWriter) at java.io.PrintWriter.println(PrintWriter.java:585) at java.io.PrintWriter.println(PrintWriter.java:696) - locked <0xc9553ae0> (a java.io.BufferedWriter) at qstatsClient.main(qstatsClient.java:337) "VM Thread" prio=3 tid=0x0004b800 nid=0x3 runnable "VM Periodic Task Thread" prio=3 tid=0x000a3800 nid=0x9 waiting on condition
From the looks of this dump, it seems that I am dealing with a locked resource. Can anyone tell me how to get around this situation?
Thanks in advance for your comments.
Frustrated programmer