StructuredExecutor Incompatible with HttpClient?
Eric Kolotyluk
eric at kolotyluk.net
Mon Nov 29 14:50:20 UTC 2021
@Alan Bateman <Alan.Bateman at oracle.com>
Thanks for trying my example...
1. Using newThreadPerTaskExecutor() with virtual threads does seem to
work fine.
- However, it's the StructuredExecutor that I really want to test.
2. Did you also run the case with the synchronous HTTP request?
- Earlier you implied this should work, but it also failed for me.
3. Are you saying that StructuredExecutor will never work with the
asynchronous HTTP client?
- I am building the HTTP client with the StructuredExecutor, so why
is the client using threads outside of the tree?
Cheers, Eric
On Mon, Nov 29, 2021 at 12:08 AM Alan Bateman <Alan.Bateman at oracle.com>
wrote:
> 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