Skip to content
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

MaxConcurrency annotation #136

Open
smillidge opened this issue Mar 17, 2021 · 10 comments
Open

MaxConcurrency annotation #136

smillidge opened this issue Mar 17, 2021 · 10 comments
Labels
enhancement New feature or request
Milestone

Comments

@smillidge
Copy link
Contributor

Annotation to define max concurrency for access to a method or bean. This was first mooted on the EJB spec but adding to concurrency would mean this could be used generally across the platform.

See javaee/ejb-spec#9

Also see https://download.eclipse.org/microprofile/microprofile-fault-tolerance-2.1/apidocs/org/eclipse/microprofile/faulttolerance/Bulkhead.html

@smillidge smillidge added this to the 3.0 milestone Mar 17, 2021
@smillidge
Copy link
Contributor Author

If we have the new Async annotation I think we can have a very simple definition with just a single attribute for maxConcurrency and rely on Semaphore isolation. As the new Async annotation allows the developer to specify the specific ExecutorService which can be configured to have a maxAsync. Thread isolation can be acheived using the Async annotation and a ExecutorService with a configured maxAsync

@njr-11 njr-11 modified the milestones: 3.0, 3.1 Jan 13, 2022
@smillidge smillidge added the enhancement New feature or request label Dec 19, 2022
@edburns
Copy link

edburns commented Sep 26, 2023

Any word on getting this in for EE 11?

@smillidge
Copy link
Contributor Author

it's tagged as a candidate for 3.1 which is the Jakarta EE 11 release. I don't think any work has been done yet though.

@KyleAure KyleAure modified the milestones: 3.1.0, 3.2.0 Jul 1, 2024
@njr-11
Copy link
Contributor

njr-11 commented Jan 15, 2025

It seems like the most important part of this is already covered by Asynchronous/executor with maxAsync, and all that remains is semaphore isolation. I am wondering what the value is of providing a @MaxConcurrency to enforce sempahore isolation when a user can already do that with java.util.concurrent.Sempahore and other classes of java.util.concurrent. How much benefit does the user get from having the Jakarta EE product provider hold onto the semaphore for them and automatically invoke it upon entry and exit from methods of a class? Is there more to this that I am not aware of?

@m-reza-rahman
Copy link

m-reza-rahman commented Jan 20, 2025

To remind of the original reason I proposed this, I don't think this should be coupled with @async, which is a totally separate use case (I think the same mistake/misunderstanding happened with @schedule). Even if it works functionally, the semantics are very confusing.

The original intent was for a way to provide an equivalent to how EJB pooling effectively causes bandwidth throttling at the component level. This should be applicable to any CDI bean that can be concurrently accessed. This is an important missing piece for EJB users that see this type of functionality as valuable. Here are the two original code examples provided:

@rokon12
Copy link
Contributor

rokon12 commented Jan 20, 2025

I believe this could be highly beneficial for virtual threads. Since virtual threads can be created in virtually unlimited numbers, we often need a way to throttle them, such as using a semaphore. In this context, having an @maxConcurrency annotation would be particularly useful.

@AngeloRubens
Copy link

AngeloRubens commented Jan 21, 2025

I also think it's important to have this feature, you can see this first sample RI for CDI context https://github.com/omnifaces/omniservices....

regards

@lprimak
Copy link

lprimak commented Jan 22, 2025

Big +1 for @Service Annotation. I would think that @Service(maxConcurrency = 10) would be great without a separate annotation. Default being what's configured by the platform

@m-reza-rahman
Copy link

m-reza-rahman commented Jan 22, 2025

There are two reasons for aiming for a separate annotation. The primary one is treating this as a cross-cutting concurrency feature that can be applied to a variety of CDI components as users wish. Also, as far as I am aware, stereotypes themselves are not bound to interceptors directly and typically do not have attributes defined.

I can see this, however, as an attribute of @Lock or something that works with @Lock.

@lprimak
Copy link

lprimak commented Jan 22, 2025

Understood. That also works for me. +1 for MaxConcurrency annotation

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

No branches or pull requests

8 participants