A new build and a new structured concurrency API
Alex Otenko
oleksandr.otenko at gmail.com
Wed Nov 17 22:41:38 UTC 2021
Hi Remi,
Yes, from the docs onComplete is not always invoked, and I wonder what is
being saved.
Yes, lambdas can capture the things from outside syntactic scope, but can't
share things between themselves. Hence the question. Say, if I borrow a
connection inside Callable, onComplete seems like the right place to
release it. No? If that's not the purpose, what does onComplete achieve
that can't be done in, say, finally clause of Callable?
Alex
On Wed, 17 Nov 2021, 22:20 Remi Forax, <forax at univ-mlv.fr> wrote:
> ----- Original Message -----
> > From: "Alex Otenko" <oleksandr.otenko at gmail.com>
> > To: "Ron Pressler" <ron.pressler at oracle.com>
> > Cc: "loom-dev" <loom-dev at openjdk.java.net>
> > Sent: Mercredi 17 Novembre 2021 22:48:07
> > Subject: Re: A new build and a new structured concurrency API
>
> > Thanks for the great update.
> >
> > I am trying to comprehend the implications of fork with onComplete.
>
> Hi Alex,
>
> >
> > The docs say onComplete may not be invoked at all. What is being saved
> > here, compared to cancel() that guarantees onComplete will be invoked.
>
> From the doc, onComplete() is not called if the structured executor is
> already shutdown.
>
> >
> > The other thing that seems odd is that onComplete is entirely
> > side-effecting: it has no communication with the task that got completed
> > (the task can't delegate responsibility for anything), and no
> communication
> > with the consumer of Future (onComplete can't delegate responsibility for
> > anything). Like, I borrow a connection - who's going to return it and
> how?
> > I'd expect someone to have one last glance at the context of the Callable
> > to clean up.
>
> onComplete takes a BiConsumer which is a functional interface so the
> lambda can capture any context,
> the same way a Callable can capture the same context.
>
> >
> > Alex
>
> regards,
> Rémi
>
> >
> > On Mon, 15 Nov 2021, 20:22 Ron Pressler, <ron.pressler at oracle.com>
> wrote:
> >
> >> Hi.
> >>
> >> We have just published a new Early Access build of Project Loom over on
> >> https://jdk.java.net/loom/
> >>
> >> The build is based on jdk-18+22, and now requires the --enable-preview
> >> flag to
> >> use Loom features (when compiling, remember to also add `--release 18`).
> >>
> >> The main new feature in this build is a new API for structured
> concurrency,
> >> called StructuredExecutor. To learn more about its motivation,
> >> capabilities,
> >> and use, please read this JEP draft [1] and the Javadoc [2]. Pay special
> >> attention to the new methods added to Future, resultNow and exceptionNow
> >> [3], and how they complement StructuredExecutor. One of the most
> exciting
> >> capabilities of StructuredExecutor is the new structured thread-dump
> >> mentioned
> >> in the JEP draft.
> >>
> >> Another new feature is the ability to use virtual threads as Cleaner
> >> threads
> >> [4]. We have also published a draft JEP for virtual threads [5]. The
> JEPs,
> >> like
> >> the project, are still a work in progress.
> >>
> >> As always, we appreciate feedback on these features from those who try
> >> them.
> >> Please, download the new EA and tell us about your experience.
> >>
> >> -- Ron
> >>
> >> [1]: http://openjdk.java.net/jeps/8277129
> >> [2]:
> >>
> https://download.java.net/java/early_access/loom/docs/api/java.base/java/util/concurrent/StructuredExecutor.html
> >> [3]:
> >>
> https://download.java.net/java/early_access/loom/docs/api/java.base/java/util/concurrent/Future.html
> >> [4]:
> >>
> https://download.java.net/java/early_access/loom/docs/api/java.base/java/lang/ref/Cleaner.html
> >> [5]: http://openjdk.java.net/jeps/8277131
> >>
>
More information about the loom-dev
mailing list