JDK+libthr on STABLE



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();
}
}
}
_______________________________________________
freebsd-stable@xxxxxxxxxxx mailing list
http://lists.freebsd.org/mailman/listinfo/freebsd-stable
To unsubscribe, send any mail to "freebsd-stable-unsubscribe@xxxxxxxxxxx"



Relevant Pages

  • Re: Java Applet pulled from VMS Web Server
    ... anything to work and 2) I will go to my grave before deploying a "Java ... to use FTP as the protocol to upload the .JAR applet ... private String host; ... public void update { ...
    (comp.os.vms)
  • Re: Function pointers (callbacks) in Java
    ... Java is using an array of indexed command objects that all implement from an ... abstract class CallBackObject extends Exception ... private Object ... public void doCallBack() throws Exception ...
    (comp.lang.java.programmer)
  • Re: I am a Java Virgin! I need your support.
    ... Why am I learning Java you ask? ... Actually thanks to Google and Mozilla Firefox (especially Google who I ... public void doSomething{ ... They generally do that for the classes and packages they ...
    (comp.lang.java.programmer)
  • Re: Runtime
    ... be able to get any output streams from the swing program ... public void runswing ... //Str18 is the string to run the java program with the java intreperter ... public class JButtons implements ActionListener ...
    (comp.lang.java.programmer)
  • Re: Delegates...?
    ... Buried in that article is actually an example of how a behavior similar to delegates in C# can be implemented in Java. ... I don't really know that this is the _best_ way, but it is how I've been dealing with the lack of delegate types, and the article Lew posted appears to suggest that's in fact how the Java designers expect you deal with it. ... private event EventDelegate Test; ... public void SubscribeTestEvent ...
    (comp.lang.java.programmer)