[External] : Re: A new build and a new structured concurrency API

Eric Kolotyluk eric at kolotyluk.net
Tue Nov 16 00:55:30 UTC 2021


I wanted to comment on https://bugs.openjdk.java.net/browse/JDK-8277129 but
I don't have login credentials.

Looking at the JEP I am still trying to understand why close() throws an
exception if join() has not been called. It's rather unsatisfying to just
be told it must be called without some rationale. Intuitively, I feel that
exiting a try-with-resources block should just take care of business, and
should be part of Structured Concurrency. In the current implementation, it
seems like the StructuredExecutor adds its own boundaries that don't play
well with the try-with-resources pattern.

Is this situation because canceling and exception handling have not been
fully worked out?

Cheers, Eric

On Mon, Nov 15, 2021 at 3:33 PM Eric Kolotyluk <eric at kolotyluk.net> wrote:

> Okay, I was able to trick IntelliJ into running my uber-jar, but still can
> just run code via normal methods...
>
> try (var executorService = StructuredExecutor.open("", Thread.ofVirtual().factory())) {
>     IntStream.range(0, 15).forEach(item -> {
>         System.out.println("item = " + item + ", Thread ID = " + Thread.currentThread());
>         executorService.fork(() -> {
>             System.out.println("\ttask = " + item + ", Thread ID = " + Thread.currentThread());
>             return null;
>         });
>     });
> }
>
> Exception in thread "main" java.lang.IllegalStateException: Owner did not
> invoke join or joinUntil
> at
> java.base/java.util.concurrent.StructuredExecutor.close(StructuredExecutor.java:622)
> at net.kolotyluk.loom.Experiment00.main(Experiment00.java:28)
>
> So, what is the rationale behind explicitly requiring 'join' or
> 'joinUntil'? Why can't close() at the end of the try-block implicitly deal
> with that?
>
> Cheers, Eric
>


More information about the loom-dev mailing list