8086208: java/lang/ProcessHandle/OnExitTest.java: IllegalThreadStateException: process hasn't exited

Reviewed-by: martin, dholmes
This commit is contained in:
Roger Riggs 2015-06-17 16:03:49 -04:00
parent 1534835fb7
commit cacb730235
2 changed files with 16 additions and 5 deletions

View File

@ -542,7 +542,22 @@ final class ProcessImpl extends Process {
@Override
public CompletableFuture<Process> onExit() {
return ProcessHandleImpl.completion(pid, false)
.handleAsync((exitStatus, unusedThrowable) -> this);
.handleAsync((exitStatus, unusedThrowable) -> {
boolean interrupted = false;
while (true) {
// Ensure that the concurrent task setting the exit status has completed
try {
waitFor();
break;
} catch (InterruptedException ie) {
interrupted = true;
}
}
if (interrupted) {
Thread.currentThread().interrupt();
}
return this;
});
}
@Override

View File

@ -26,21 +26,17 @@ import java.lang.InterruptedException;
import java.time.Duration;
import java.time.Instant;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;
import java.util.concurrent.ArrayBlockingQueue;
import java.util.concurrent.CompletableFuture;
import java.util.concurrent.ConcurrentHashMap;
import java.util.concurrent.ExecutionException;
import java.util.stream.Collectors;
import jdk.testlibrary.Platform;
import org.testng.annotations.Test;
import org.testng.Assert;
import org.testng.TestNG;
/*
* @test
* @library /lib/testlibrary
* @summary Functions of Process.onExit and ProcessHandle.onExit
* @author Roger Riggs
*/