StructuredExecutor Incompatible with HttpClient?

Alan Bateman Alan.Bateman at oracle.com
Mon Nov 29 08:08:17 UTC 2021


On 28/11/2021 21:17, Eric Kolotyluk wrote:
> :
>
> TimeoutException
> Exception in thread "main" java.lang.IllegalStateException: Task was 
> cancelled
> at 
> java.base/java.util.concurrent.FutureTask.resultNow(FutureTask.java:218)
> at 
> java.base/java.util.concurrent.StructuredExecutor$FutureImpl.resultNow(StructuredExecutor.java:726)
> at 
> net.kolotyluk.loom.Experiment20_HttpClient.main(Experiment20_HttpClient.java:90)
>
> Process finished with exit code 1
>
So an exception is thrown because the deadline has expired and code in 
the catch block calls Future::resultNow without checking the status, is 
that right?

I ran your example with -Djdk.httpclient.HttpClient.log=all and it 
revealed the exception:

INFO: ERROR: HttpClient-1-SelectorManager: HttpClientImpl shutting down 
due to fatal error: java.lang.IllegalStateException: Current thread not 
owner or thread in flock
         at 
java.base/jdk.internal.misc.ThreadFlock.ensureOwnerOrContainsThread(ThreadFlock.java:204)
         at 
java.base/jdk.internal.misc.ThreadFlock.start(ThreadFlock.java:267)
         at 
java.base/java.util.concurrent.StructuredExecutor.spawn(StructuredExecutor.java:351)
         at 
java.base/java.util.concurrent.StructuredExecutor.execute(StructuredExecutor.java:455)
         at 
java.net.http/jdk.internal.net.http.HttpClientImpl$DelegatingExecutor.execute(HttpClientImpl.java:153)
         at 
java.net.http/jdk.internal.net.http.PlainHttpConnection$ConnectEvent.handle(PlainHttpConnection.java:152)
         at 
java.net.http/jdk.internal.net.http.HttpClientImpl$SelectorManager.handleEvent(HttpClientImpl.java:977)
         at 
java.net.http/jdk.internal.net.http.HttpClientImpl$SelectorManager.lambda$run$3(HttpClientImpl.java:932)
         at java.base/java.util.ArrayList.forEach(ArrayList.java:1511)
         at 
java.net.http/jdk.internal.net.http.HttpClientImpl$SelectorManager.run(HttpClientImpl.java:932)

A StructuredExecutor may be an Executor but it won't execute tasks from 
threads that aren't in the tree, which is what is happening here when 
the HTTP client is used in async mode and configured to use this executor.

-Alan.


More information about the loom-dev mailing list