-
Notifications
You must be signed in to change notification settings - Fork 38
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Interoperability with Structured Concurrency #272
Comments
For my opinion, the structured task scope is similar to Kotlin Coroutines scope in concept. I think adding an annotation(the functionality is similar to Kotlin But like async support, how to support the context prorogation seamlessly in background without copying context data explicitly . |
This was only a preview in Java 21, so this can be considered for EE12 |
Structured Concurrency has been in incubation in Java 19 and 20 and might be part of Java 21, in which case the Concurrency specification should address how it pertains to Jakarta EE.
The main way of interacting with Structured Concurrency is StructuredTaskScope, which has a fork method that accepts a
Callable
task. There is no way provided for the Jakarta EE Concurrency specification to automatically tie into it.There are some steps that users can take manually to leverage existing APIs from the Jakarta EE Concurrency specification to ensure that their tasks run with context.
At the most granular level, you can use the ContextService.contextualCallable method that we added in Jakarta EE 10 to pre-contextualize Callables that you supply to the fork method.
There is also a constructor that you can use to designate a specific ThreadFactory to be used by the StructuredTaskScope. The ThreadFactory could be a ManagedThreadFactory,
The above is what will be possible if we don't do anything new in the Jakarta EE Concurrency spec for this. There will be the above ways of contextualizing tasks, but no ways of constraining concurrency.
StructuredTaskScope can be extended with subclasses. It even provides a couple of built-in ones:
https://download.java.net/java/early_access/jdk20/docs/api/jdk.incubator.concurrent/jdk/incubator/concurrent/StructuredTaskScope.ShutdownOnFailure.html
https://download.java.net/java/early_access/jdk20/docs/api/jdk.incubator.concurrent/jdk/incubator/concurrent/StructuredTaskScope.ShutdownOnSuccess.html
The Jakarta EE Concurrency specification could do something with subclasses and maybe let you obtain StructuredTaskScopes from managed executors if we thought that would be useful. More investigation is needed.
The text was updated successfully, but these errors were encountered: