A new build and a new structured concurrency API
Mike Rettig
mike.rettig at gmail.com
Mon Nov 15 22:01:17 UTC 2021
>From the JEP:
"It is not a goal to propose a new task/thread cancellation mechanism to
supersede the existing interruption mechanism. This might be addressed by a
future JEP."
I think the cancellation mechanism needs to be addressed first. The
"correct" way to handle thread interrupts is already unclear in many cases.
Requiring it to mean "cancel" when used with structured concurrency is
going to be difficult for developers. The interrupt api lacks explicitness
and usage is inconsistent.
>From the current tutorial from Oracle :
https://docs.oracle.com/javase/tutorial/essential/concurrency/interrupt.html
"An *interrupt* is an indication to a thread that it should stop what it is
doing and do something else. It's up to the programmer to decide exactly
how a thread responds to an interrupt, but it is very common for the thread
to terminate."
I've tried to use interrupts for cancelling. Interrupt handling code is
often buried in third party code. To use interrupts I had to find and
verify that all the interrupts were handled "correctly". It gets even
trickier when code paths reach points that should no longer be cancelled.
Rather than using interrupts, it is usually a much better approach to
create explicit api's that support cancels (e.g. cancel a long running
network operation by closing the socket).
Mike
On Mon, Nov 15, 2021 at 2:22 PM 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