-
Notifications
You must be signed in to change notification settings - Fork 39
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
Add @Asynchronous Annotation #43
Comments
In my view this would essentially execute the method using the Managed Executor submit api. The annotation name could specify the JNDI name of the Executor to use with the standard default executor used if no other is specified. |
The MicroProfile FaultTolerance FYI - There is also an issue open under MicroProfile FaultTolerance with some discussion that |
The EJB The javadoc for the MicroProfile FaultTolerence
|
Another difference is that MicroProfile FaultTolerance That said, the The first would be as MicroProfile/EJB have done where the invoker of the asynchronous method gets a [Completable]Future for the [Completable]Future that is created and returned by the method itself. It doesn't get the same [Completable]Future instance, because, being asynchronous, the method doesn't even have the opportunity to create it yet. Thus, there are two [Completable]Future instances involved, with the invoker having what is essentially a copy of the other. In this case, it would be wrong for cancellation (or forced completion by any other means -- there are several) of the invoker's copy (which is a dependent stage in CompletableFuture terms) to have any impact on the original. That would violate how completable futures work, and is likely the reason why MicroProfile FaultTolerance stays out of the way here and doesn't offer a cancel operation. In terms of CompletableFuture, a dependent stage can be impacted by the completion of a stage upon which it depends (the one returned by the method impl) but not the other way around. If you cancel (or forcibly complete by other means) a dependent stage, it impact the stage itself, but any stage that it depended on must be unimpacted. If cancel of the stage created by the asynchronous method impl is important, there would need to be a dedicated API specifically for that purpose, not a reuse of the dependent stage which already has a different meaning of its own.
The second option here -- if we wanted to allow a cancel on the [Completable]Future to actually flow through, would be to design it such that the Asynchronous method doesn't create its own [Completable]Future, but instead obtains an incomplete Future via some API,
|
Something else to consider as an alternative to In this case, you don't need any annotation at all if the methods don't have parameters, for example,
which can be invoked as follows:
And if ManagedExecutorService were further enhanced with a couple of additional trivial methods,
then you would also be able to take methods with 1 or 2 parameters like these,
and get the equivalent of async methods via
but to go any further, you would need more functional interfaces (and equivalent ManagedExecutorService apply methods) taking higher numbers of parameters. I really like the straightforwardness and consistency of this approach (the method to be run asynchronously is just a normal method with its natural signature and return value), but it's a pretty big problem that there is no way to allow for a variable number of parameters, so it's too limited in that way. I thought I would bring it up though in case someone does see how to solve that problem. |
I'm doing some initial experimentation with this in the Open Liberty repo under OpenLiberty/open-liberty#18484 which currently has a draft Async annotation class with some initial JavaDoc. It looks promising thus far. Once I get further along on it, I'll create a pull in the spec repo. |
Signed-off-by: Nathan Rauh <[email protected]>
Pull #147 is available for review. It attempts to address a variety of usage patterns and also ties in with the managed CompletableFuture support in Concurrency 3.0. It doesn't provide an alternative to every pattern that EJB has, meaning we would end up with a situation where the existing Asynchronous remains for EJB to use versus this new Async annotation for everywhere else. |
Can we pick up the remaining EJB functionality? |
Looking through Tracy's list of differences with EJB for the remaining EJB functionality,
Hopefully this gets us close enough. Let me know if you have any other ideas. |
From my list of difference above, only the first is really a difference in capability..... the rest are all concerns related to the question: can the new For example:
Both EJB and WAR modules have this However, I see the current proposal is that the new |
Signed-off-by: Nathan Rauh <[email protected]>
…r document transactional
@tkburroughs has a good point here. I agree with the above comments. We should just say this annotation applies to CDI beans that are not EJBs as EJBs are CDI beans. We should just leave EJB spec at rest and not to touch it. |
… usage from EJB
Signed-off-by: Nathan Rauh <[email protected]>
…r document transactional
… usage from EJB
I know I'm late to the party and the issue is closed already, but just for reference; the above is not correct on two accounts. JSF no longer has its own managed beans. They were deprecated in 2.3, and removed in 4.0. Also, JSF managed beans were never a special case of a CDI managed bean. They were a totally different kind of bean, that only (like Servlets) emulates a few capabilities regarding injection. |
EJB and MicroProfile Fault Tolerance each have their own Asynchronous annotation. This seems like the kind of thing that should belong under the concurrency spec, with the other specs expanding upon it as required.
At a base level, it would simply mean that a method gets executed using a separate thread (with the method returning a Future). This could then be extended in a number of ways, such as specifying the name of a preconfigured ExecutorService to use (rather than always using the default one).
The text was updated successfully, but these errors were encountered: