Skip to content

Commit 52cd38e

Browse files
committed
Work around missing executor.close()
1 parent c9de0cc commit 52cd38e

File tree

1 file changed

+24
-1
lines changed

1 file changed

+24
-1
lines changed

test/jdk/java/net/httpclient/SmallTimeout.java

Lines changed: 24 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -181,7 +181,30 @@ public static void main(String[] args) throws Exception {
181181
checkReturn(requests);
182182

183183
// shuts down the executor and awaits its termination
184-
executor.close();
184+
//executor.close();
185+
// In 17, ExecutorService does not implement close().
186+
// I derived this from the implementation of the method
187+
// in 21.
188+
{
189+
boolean terminated = executor.isTerminated();
190+
if (!terminated) {
191+
executor.shutdown();
192+
boolean interrupted = false;
193+
while (!terminated) {
194+
try {
195+
terminated = executor.awaitTermination(1L, TimeUnit.DAYS);
196+
} catch (InterruptedException e) {
197+
if (!interrupted) {
198+
executor.shutdownNow();
199+
interrupted = true;
200+
}
201+
}
202+
}
203+
if (interrupted) {
204+
Thread.currentThread().interrupt();
205+
}
206+
}
207+
}
185208

186209
if (error)
187210
throw new RuntimeException("Failed. Check output");

0 commit comments

Comments
 (0)