StructuredExecutor Incompatible with HttpClient?

Eric Kolotyluk eric at
Mon Nov 29 14:50:20 UTC 2021

@Alan Bateman <Alan.Bateman at>

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>

> 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(
> at
> java.base/java.util.concurrent.StructuredExecutor$FutureImpl.resultNow(
> at
> net.kolotyluk.loom.Experiment20_HttpClient.main(
> 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(
>         at
> java.base/jdk.internal.misc.ThreadFlock.start(
>         at
> java.base/java.util.concurrent.StructuredExecutor.spawn(
>         at
> java.base/java.util.concurrent.StructuredExecutor.execute(
>         at
>         at
>         at
>         at
>         at java.base/java.util.ArrayList.forEach(
>         at
> 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