Hi David,

Neither of these return immediately:

@Path("/abc")
@Stateless
@javax.ejb.TransactionAttribute(TransactionAttributeType.NEVER)
public class BasicResource {
    @GET
    @Produces(MediaType.APPLICATION_JSON)
    public void test(@Suspended final AsyncResponse asyncResponse) {
        asyncResponse.resume(Response.ok("Hello world").build());
        sleep();
    }
    private void sleep() {
        try {
            Thread.sleep(3000);
        } catch (Exception e) {
        }
    }
}

@Path("/abc")
public class BasicResource {
    @GET
    @Produces(MediaType.APPLICATION_JSON)
    public void test(@Suspended final AsyncResponse asyncResponse) {
        asyncResponse.resume(Response.ok("Hello world").build());
        sleep();
    }
    private void sleep() {
        try {
            Thread.sleep(3000);
        } catch (Exception e) {
        }
    }
}

Paul


On Sat, Oct 19, 2019 at 1:23 AM David Jencks <[email protected]>
wrote:

> IIUC this method is running inside the container managed transaction?
> Does it send the response immediately if it’s not in a container managed
> transaction?
>
> david jencks
>
> > On Oct 18, 2019, at 10:21 AM, Paul Carter-Brown
> <[email protected]> wrote:
> >
> > Hi,
> >
> > In this code sample, why is it that it takes 3s for the "OK" response to
> > get back to the client.
> > My expectation would be that the response would go back immediately?
> >
> > @Path("/abc")
> > @Stateless
> > public class BasicResource {
> >
> >    @PersistenceContext()
> >    private EntityManager em;
> >
> >    @GET
> >    @Produces(MediaType.TEXT_PLAIN)
> >    public void test(@Suspended final AsyncResponse asyncResponse) {
> >        // Want OK to get to the client immediately
> >        asyncResponse.resume("OK");
> >        try {
> >            // Some long running JDBC transactional stuff to run in JTA
> > container managed transaction using injected em
> >            // That must commit when done
> >            Thread.sleep(3000);
> >        } catch (Exception e) {
> >        }
> >    }
> > }
> >
> > Paul
>
>

Reply via email to