From owner-freebsd-stable@FreeBSD.ORG Fri May 30 09:38:41 2008 Return-Path: Delivered-To: stable@freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2001:4f8:fff6::34]) by hub.freebsd.org (Postfix) with ESMTP id 1915A106566B for ; Fri, 30 May 2008 09:38:41 +0000 (UTC) (envelope-from huang@gddsn.org.cn) Received: from gddsn.org.cn (gddsn.org.cn [218.19.164.145]) by mx1.freebsd.org (Postfix) with ESMTP id 7E5B28FC1A for ; Fri, 30 May 2008 09:38:28 +0000 (UTC) (envelope-from huang@gddsn.org.cn) Received: from tp.gddsn.org.cn (unknown [124.81.160.97]) (using TLSv1 with cipher DHE-RSA-AES256-SHA (256/256 bits)) (No client certificate requested) by gddsn.org.cn (Postfix) with ESMTP id CAFC538CB89; Wed, 28 May 2008 23:10:20 +0800 (CST) Message-ID: <483D75D7.10907@gddsn.org.cn> Date: Wed, 28 May 2008 15:10:15 +0000 From: Huang wen hui User-Agent: Thunderbird 2.0.0.12 (X11/20080421) MIME-Version: 1.0 To: stable@freebsd.org, java Content-Type: text/plain; charset=GB2312 Content-Transfer-Encoding: 7bit Cc: Subject: JDK+libthr on STABLE X-BeenThere: freebsd-stable@freebsd.org X-Mailman-Version: 2.1.5 Precedence: list List-Id: Production branch of FreeBSD source code List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Fri, 30 May 2008 09:38:41 -0000 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 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 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[] 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 { 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(); } } }