test/java/lang/ProcessBuilder/CloseRace.java
Print this page
@@ -31,20 +31,24 @@
*/
import java.io.*;
import java.util.ArrayList;
import java.util.List;
+import java.util.concurrent.CountDownLatch;
public class CloseRace {
private static final String BIG_FILE = "bigfile";
private static final int[] procFDs = new int[6];
/** default value sufficient to repro bug 8024521. */
private static final int testDurationSeconds
= Integer.getInteger("test.duration", 600);
+ private static final CountDownLatch startedSignal
+ = new CountDownLatch(2);
+
static boolean fdInUse(int i) {
return new File("/proc/self/fd/" + i).exists();
}
static boolean[] procFDsInUse() {
@@ -82,20 +86,22 @@
new Thread(new ExecLoop()),
};
for (Thread thread : threads)
thread.start();
+ startedSignal.await();
Thread.sleep(testDurationSeconds * 1000);
for (Thread thread : threads)
thread.interrupt();
for (Thread thread : threads)
thread.join();
}
static class OpenLoop implements Runnable {
public void run() {
+ startedSignal.countDown();
while (!Thread.interrupted()) {
try {
// wait for ExecLoop to finish creating process
do {} while (count(procFDsInUse()) != 3);
List<InputStream> iss = new ArrayList<>(4);
@@ -118,10 +124,11 @@
}
}
static class ExecLoop implements Runnable {
public void run() {
+ startedSignal.countDown();
ProcessBuilder builder = new ProcessBuilder("/bin/true");
while (!Thread.interrupted()) {
try {
// wait for OpenLoop to finish
do {} while (count(procFDsInUse()) > 0);