diff -r 1a13210ce726 -r 45c88bf0592b test/jdk/java/net/httpclient/http2/BasicTest.java --- a/test/jdk/java/net/httpclient/http2/BasicTest.java Fri Nov 24 18:42:32 2017 +0000 +++ b/test/jdk/java/net/httpclient/http2/BasicTest.java Fri Nov 24 20:48:35 2017 +0000 @@ -40,7 +40,10 @@ import javax.net.ssl.*; import java.nio.file.*; import java.util.concurrent.*; +import java.util.concurrent.atomic.AtomicReference; +import java.util.Collections; import java.util.LinkedList; +import java.util.List; import jdk.testlibrary.SimpleSSLContext; import static jdk.incubator.http.HttpRequest.BodyPublisher.fromFile; import static jdk.incubator.http.HttpRequest.BodyPublisher.fromString; @@ -87,14 +90,23 @@ } } - static LinkedList> cfs = new LinkedList<>(); + static List> cfs = Collections + .synchronizedList( new LinkedList<>()); + + static AtomicReference> currentCF = + new AtomicReference<>(); static class EchoWithPingHandler extends Http2EchoHandler { @Override public void handle(Http2TestExchange exchange) throws IOException { - CompletableFuture cf = new CompletableFuture<>(); - cfs.add(cf); - exchange.sendPing(cf); + // ensure only one ping active at a time. + currentCF.getAndUpdate((cf) -> { + if (cf == null || cf.isDone()) { + cf = exchange.sendPing(); + cfs.add(cf); + } + return cf; + }); super.handle(exchange); } }