eclipse-ee4j / jersey

Eclipse Jersey Project - Read our Wiki:
https://github.com/eclipse-ee4j/jersey/wiki
Other
692 stars 355 forks source link

Repalcement of EJB @Asynchronous and @Suspend AysncResponse #5099

Open hantsy opened 2 years ago

hantsy commented 2 years ago

In the traditional Jaxrs2.x (Java EE7/8), there are several approaches to support async response in Jaxrs.

We can use ejb @Asychronous and @Suspend AsyncResponse like this.

@Path("ejb")
@Stateless
public class EjbAsyncResource {

    @Inject
    Logger LOG;

    @GET
    @Asynchronous // from ejb
    public void getAsync(final @Suspended AsyncResponse res) {

        //perform long run operations.
        try {
            LOG.log(Level.INFO, " execute long run task in EjbAsyncResource");
            Thread.sleep(500);
        } catch (InterruptedException ex) {
            LOG.log(Level.SEVERE, "error :" +ex.getMessage());
        }

        res.resume(Response.ok("Asynchronus EJB resource").build());
    }

}

And as planned in the future Jakarta EE specs, the EJB will be replaced with new CDI compatible replacement.

Currently, there is a new @Asynchronous added in the concurrency 3.0 spec. But it seems this annotation can not replace the ejb @Asynchronous in the above case.

jansupol commented 2 years ago

This sounds more like a request on the Specification project. Jakarta REST 4.0 plans to use CDI as the injection framework, which will cause a change in the resource method signatures. Using @Asynchronous sounds like something that could be used.

jansupol commented 2 years ago

On the other hand, concurrency is not part of Jakarta EE core-profile, unlike the Jakarta REST, so the Jakarta REST can hardly be depending on it. Perhaps ObservesAsync could be used.