-
Notifications
You must be signed in to change notification settings - Fork 30
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
Asynchronous repository methods and integration with Jakarta Concurrency #19
Comments
@njr-11 Have you seen and read #17? Whether or not to separate the basic repository types like |
Yes, I've seen issue #17, although I missed that you had mentioned CompletableFuture there and thought it was only about fully reactive patterns. Thanks for opening that, it will be important to have that discussion. Issue 19 with the idea for potential integration with Jakarta Concurrency Asynchronous was meant to be an entirely separate and unrelated proposal of its own because it is independent of the repository type, meant for custom repository methods in general, and for the most part just relies on what is already in another Jakarta spec. The idea to allow CompletableFuture as a return type is an overlap with 17 though, so sorry that I missed that aspect. |
The concurrency/reactive will be the one that we'll spend more time on, especially on the discussion. Perhaps, start with the easy ones: CrudRepository and the paginating then go to reactive |
I would like to point to my comment here: #17 (comment), which is also relevant to this issue. Long story short: we essentially already have this feature. |
Yes, we are really close to already having it. We should keep this issue open, and I'll assign it to Future to look into next release, because it would be nice to standardize the additional return types that can be used to make this work rather than the user needing to rely on vendor-specific extensions/documentation to say that the additional return types are allowed. |
Yes, of course, agreed. |
Description
As a:
...I need to be able to:
write repository methods that run asynchronously
...which enables me to:
avoid tying up the requesting thread waiting for queries to finish so that I can complete other work in the mean time.
Note: This issue does not cover reactive programming models like Flow. That is a separate discussion.
The preference would be to rely on the data access provider's own async support, but Jakarta Persistence/JPA (which are JDBC based) doesn't have async support. Lacking that, Jakarta Concurrency @Asynchronous could provide what we need in this area and fit quite well with just some minor language added to the Jakarta Data spec to make it possible.
If we specify that repository methods can have return types of CompletionStage and CompletableFuture (as some implementations already do), then based on the data access provider's level of support for async:
@Asynchronous
then that same@Asynchronous
annotation is also applied to the bean instance. Doing that will automatically trigger the Concurrency 3.0 interceptor. Then all the implementation needs to do is return an already-completed future, relying on the Concurrency@Asynchronous
interceptor to cover making it async.Other benefits of this will be that if the data access provider, such as based on a Jakarta Persistence/JPA implementation, requires the async thread to have services of the Jakarta EE platform available, such as performing a java:comp/env lookup of a data source, or to be able to run under a transaction, or to have the same security credentials on the thread for performing the database operation, the Jakarta Concurrency spec will have taken care of all of that for us.
The text was updated successfully, but these errors were encountered: