@Suspended or asynchronous operation

JAX-RS 2.1 got a brand new reactive API to integrate with Java 8 CompletionStage but the server also has a nice integration to be reactive: @Suspended. For instance, the findAll method of QuoteResource could look like the following:

@Path("quote")@RequestScopedpublic class QuoteResource {    @Inject    private QuoteService quoteService;    @Resource    private ManagedExecutorService managedExecutorService;    @GET    public void findAll(@Suspended final AsyncResponse response, <1>                        @QueryParam("from") @DefaultValue("0") final int from,                        @QueryParam("to") @DefaultValue("10") final int to) {        managedExecutorService.execute(() -> { <2>            try {              final long total = quoteService.countAll();              final List<JsonQuote> items = quoteService ...

Get Java EE 8 High Performance now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.