Date: Wed, 28 May 2008 15:10:15 +0000 From: Huang wen hui <huang@gddsn.org.cn> To: stable@freebsd.org, java <java@freebsd.org> Subject: JDK+libthr on STABLE Message-ID: <483D75D7.10907@gddsn.org.cn>
next in thread | raw e-mail | index | archive | help
hi, I try to run java to call external program heavily on very recent STABLE. Somtimes java hang on calling external program. ps show some <defunct> process name. 11599 p9 RL+ 0:02.77 /usr/local/jdk1.5.0/bin/java -classpath . cn/org/gddsn/test/TestShell 12431 p9 R+ 0:00.00 /usr/local/jdk1.5.0/bin/java -classpath . cn/org/gddsn/test/TestShell 12432 p9 Z+ 0:00.01 <defunct> 12433 p9 R+ 0:00.00 /usr/local/jdk1.5.0/bin/java -classpath . cn/org/gddsn/test/TestShell 12434 p9 R+ 0:00.00 /usr/local/jdk1.5.0/bin/java -classpath . cn/org/gddsn/test/TestShell 12435 p9 RL+ 0:00.00 /usr/local/jdk1.5.0/bin/java -classpath . cn/org/gddsn/test/TestShell 12436 p9 R+ 0:00.00 /usr/local/jdk1.5.0/bin/java -classpath . cn/org/gddsn/test/TestShell 12438 p9 R+ 0:00.00 /usr/local/jdk1.5.0/bin/java -classpath . cn/org/gddsn/test/TestShell and top show java suck on umtxn status. Ctl+\ also could not dump hotspot info. Both JDK5 and JDK6 have same problem. But under FreeBSD 7.0R, the problem gone. Any ideas? This is the sample java code: import java.io.BufferedReader; import java.io.File; import java.io.IOException; import java.io.InputStream; import java.io.InputStreamReader; import java.util.concurrent.Callable; import java.util.concurrent.ExecutorService; import java.util.concurrent.Executors; import java.util.concurrent.Future; public class TestShell { int maxTrial = 100; ExecutorService pool = Executors.newFixedThreadPool(10); private TrialThread[] tialThreads; public TestShell() { tialThreads = new TrialThread[maxTrial]; for (int i = 0; i < maxTrial; i++) { tialThreads[i] = new TrialThread(); } } public static void main(String[] args) { TestShell ts = new TestShell(); for (int i = 0; i < 100; i++) ts.test(); System.exit(0); } public void test() { Future<Boolean>[] futs = new Future[maxTrial]; for (int i = 0; i < maxTrial; i++) { // tialThreads[i].setTrialOrg(); futs[i] = pool.submit(tialThreads[i]); } try { for (int j = 0; j < tialThreads.length; j++) { // System.out.println(futs[j].isDone()); Boolean b = futs[j].get(); System.out.println("name: "+j+" "+b); } } catch (Exception ex) { ex.printStackTrace(); } } class TrialThread implements Callable<Boolean> { private ShellWrapper shell = new ShellWrapper(); public TrialThread() { } public Boolean call() { try { shell.shell(); } catch (Exception ex) { ex.printStackTrace(); } return new Boolean(true); } } } class ShellWrapper { public void shell() { //long now = System.currentTimeMillis(); try { final Process process = new ProcessBuilder( new String[]{ "/bin/test", ///home/hwh/try/locsat/src/LocSAT/LocSAT", "-s", "sta", "-d", "in", "-c" ,"ctl", "-o", "o" }) .directory(new File("/home/hwh/try/locsat/src/LocSAT/")) .redirectErrorStream(true).start(); /*final Process process = new ProcessBuilder(new String[] { "/bin/ls", "/" }).redirectErrorStream(true).start(); */ // System.out.println("process create time: // "+(System.currentTimeMillis()-now)); //new StreamGobbler(process.getInputStream()).start(); process.waitFor(); /** * XXX The current behavior dates back to the rewrite of the Process code * back in 1.2/1.3 which removed the dangerous buffering of all subprocess * output. In order to release all resources, user code must either invoke * Process.destroy or manually close the three subprocess streams */ // see http://bugs.sun.com/bugdatabase/view_bug.do?bug_id=4784692 //process.getErrorStream().close(); //process.getInputStream().close(); //process.getOutputStream().close(); process.destroy(); // System.out.println("shell time: "+(System.currentTimeMillis()-now)); } catch (Exception ex) { ex.printStackTrace(); } } } class StreamGobbler extends Thread { private InputStream is; StreamGobbler(InputStream is) { this.is = is; } public void run() { try { BufferedReader br = new BufferedReader(new InputStreamReader(is)); while (br.readLine() != null) ; br.close(); } catch (IOException ioe) { ioe.printStackTrace(); } } }
Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?483D75D7.10907>