StructuredExecutor Incompatible with HttpClient?

Eric Kolotyluk eric at kolotyluk.net
Sun Nov 28 21:17:30 UTC 2021


Changing the code to

            Callable<String> getActivity = () -> {
//                var response = client.sendAsync(request,
HttpResponse.BodyHandlers.ofString())
//                        .thenApply(HttpResponse::body)
//                        .join();
                var response = client.send(request,
HttpResponse.BodyHandlers.ofString()).body();
                System.out.printf("early result = %s\n", response);
                return response;
            };

changes the result to

______________________________________________________________________________

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

where line 90 is

System.out.printf("result = %s", result1.resultNow());


Cheers, Eric



On Sun, Nov 28, 2021 at 11:55 AM Alan Bateman <Alan.Bateman at oracle.com>
wrote:

> On 28/11/2021 19:19, Eric Kolotyluk wrote:
> > So, main2 seems to work as expected, but main does not
> >
> > Hello net.kolotyluk.loom.Experiment20_HttpClient
> > PID       = 35712
> > CPU Cores = 12
> > Heap Size = 6442450944 bytes
> >
> ______________________________________________________________________________
> >
> > TimeoutException
> >
> > Process finished with exit code 130
> >
> > It hangs indefinitely after TimeoutException, and I have to manually kill
> > it. The correct output should be
> >
> > Hello net.kolotyluk.loom.Experiment20_HttpClient
> > PID       = 3480
> > CPU Cores = 12
> > Heap Size = 6442450944 bytes
> >
> ______________________________________________________________________________
> >
> > early result = {"activity":"Clean out your closet and donate the clothes
> > you've
> >
> outgrown","type":"charity","participants":1,"price":0,"link":"","key":"9026787","accessibility":0.1}
> > result1 = {"activity":"Clean out your closet and donate the clothes
> you've
> >
> outgrown","type":"charity","participants":1,"price":0,"link":"","key":"9026787","accessibility":0.1}
> > Process finished with exit code 0
> I see the the examples are using the HTTP client in async mode and using
> the HttpClient.Builder to set the executor for async and dependent
> tasks. I assume the HTTP client's "selector manager" is trying to submit
> tasks via the execute method but they are being rejected because the
> "selector manager" is outside the structure. I need to lookup how to
> turn on logging on but I'll bet that is what is going on. So yes, a good
> find that it's not suitable for this usage as it's not an Executor
> implementation that anyone can ask to execute tasks.
>
> Can you try the HTTP client in synchronous mode? That is what we have
> been testing. There was one issue with interruption that was mostly
> resolved in Java 16. Using the HTTP client in async mode, without
> overriding the executor for the HTTP client to use, should be okay too.
>
> -Alan.
>


More information about the loom-dev mailing list