在一种方法中,我创建并异步发送一些 HTTPRequest,并将 CF 添加到列表中:
// HTTPClient is Java11 standard, package java.net.http;
CompletableFuture<HttpResponse<String>> httpResponseCF = this.httpClient.sendAsync(httpRequest, BodyHandlers.ofString());
list.add(httpResponseCF);
稍后,在另一种方法中,我每隔 1 秒定期检查一些异步发送的 HTTPRequest 是否已经收到:
for(CompletableFuture<HttpResponse<String>> httpResponseCF : list){
if (httpResponseCF.isDone()) {
//print out: The time between sending HTTPRequest and receiving HTTPResponse is 25ms
}
}
问题是,如何测量准确的请求时间?