Date: Sun, 6 Mar 2005 11:41:30 +0100 From: "Thomas Lange" <freebja@wie-ich.de> To: <freebsd-java@freebsd.org> Subject: Runtime.getRuntime().exec(...) -> Java process hangs in STOP state Message-ID: <004801c52239$1d13e310$16b2a8c0@bubu>
next in thread | raw e-mail | index | archive | help
Hi everyone, has anybody experienced a similar problem? I'm running tomcat with an apache / mod_jk frontend. After running a few days under medium load, a call of Runtime.getRuntime().exec(...) will not return. Also the Java process will hang infinitely in a STOP state (as displayed by top). As a result, mbufs or other resources will fill up until the entire server runs out of resources and hangs (creation of new processes is not possible anymore). I'm using FreeBSD 5.3-RELEASE-p5, jdk1.4, patchset 7. Everything (including the kernel) is compiled with -O2. Checking the output of my programm shows, that all processes created by it terminate correctly (that is, all but the last). In an ealier version (FreeBSD 4.9-RELEASE-p4), jdk1.4, patchset 6 there is a similar problem. Here calling Runtime.getRuntime().exec(...) results in creating a very high CPU load and not returning from the exec() call. My applications calls the exec()-method once every few minutes. Might it even be a threading issue? I've included a snippet from my program as an attachment. Any comments or suggestions are welcome! Regards Thomas public static boolean executeCommand(String exCommand, int exTimeout) { String command = "nice -n 15 "; command = command + exCommand; Process process = null; try { System.out.println("Executing external command " + command); process = Runtime.getRuntime().exec(command); } catch (IOException e) { System.out.println(e.toString()); return false; } InputStream inputStream = process.getInputStream(); BufferedInputStream bufferedInputStream = new BufferedInputStream(inputStream); InputStream errorStream = process.getErrorStream(); BufferedInputStream bufferedErrorStream = new BufferedInputStream(errorStream); boolean ok = false; int timeout = exTimeout; int exitValue = -999; while (!ok) { try { while (bufferedInputStream.available() > 0 || bufferedErrorStream.available() > 0) { while (bufferedInputStream.available() > 0) { System.out.print((char)bufferedInputStream.read()); } while (bufferedErrorStream.available() > 0) { System.out.print((char)bufferedErrorStream.read()); } } } catch (IOException e) { System.out.println("Couldn't read response"); } try { exitValue = process.exitValue(); ok = true; } catch (IllegalThreadStateException e) { try { // still running. Thread.sleep(300); timeout = timeout - 300; if (timeout < 0 && timeout >= -300) { System.out.println("ALERT: Command doesn't terminate:"); System.out.println(command); System.out.println("Shutting down command..."); process.destroy(); } else if (timeout <0) { System.out.println("ALERT: Command STILL doesn't terminate:"); System.out.println(command); Thread.sleep(1000); } } catch (InterruptedException e1) { // doesn't matter } } } if (ok) { // finished running if (exitValue == 0) { System.out.println("Terminated without errors"); } else { System.out.println("Exit code " + exitValue + " while performing command " + command); } } else { process.destroy(); } try { while (bufferedInputStream.available() > 0) { System.out.print((char)bufferedInputStream.read()); } while (bufferedErrorStream.available() > 0) { System.out.print((char)bufferedErrorStream.read()); } } catch (IOException e) { System.out.println("Couldn't read response"); } return exitValue == 0; }
Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?004801c52239$1d13e310$16b2a8c0>