Name: sample.async.jaxrs
Owner: WASdev
Description: This is a collection of samples that illustrate the async capabilities of JAX-RS 2.0 in Java EE7 that can be used to make your applications more responsive. #JavaEE7
Created: 2015-06-25 14:40:10.0
Updated: 2017-12-18 09:47:59.0
Pushed: 2017-10-24 19:56:17.0
Size: 154
Language: Java
GitHub Committers
User | Most Recent Commit | # Commits |
---|
Other Committers
User | Most Recent Commit | # Commits |
---|
Java EE7 added support for asynchronous request processing of REST requests in JAX-RS 2.0.
This sample contains a few variations to illustrate how to use async request processing in JAX-RS 2.0 applications. It is organized around a generic Item
, that is manipulated by an ItemService
that happens to take a long time (it sleeps for a few seconds). Each variation copes with this slow service in a different way, to illustrate how JAX-RS Async requests work and how Concurrency Utilities and EJBs can be used to offload work to other threads while keeping the EE container happy.
ItemService
to list, add, and fetch items, in the usual (synchronous) way.@Suspended
annotation with the AsyncResponse
parameter, however, it is still essentially synchronous, as the work is not offloaded to a different thread.@Asynchronous
annotation.ManagedExecutorService
defined by EE7 Concurrency Utilities in JNDI. Work for the request is then submitted to the executor and resumed later.ManagedExecutorService
injected as an @Resource.AsyncResponse
objects can be configured to handle timeouts. There are two examples showing that:
Browse the code to see what it does, or build and run it yourself:
In your browser, enter the URL for the application: http://localhost:9081/jaxrs-async/ (where port 9081 assumes the httpEndpoint provided in the sample server.xml has not been modified).
© Copyright IBM Corporation 2015, 2017.
nsed under the Apache License, Version 2.0 (the "License");
may not use this file except in compliance with the License.
may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
ss required by applicable law or agreed to in writing, software
ributed under the License is distributed on an "AS IS" BASIS,
OUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
the License for the specific language governing permissions and
tations under the License.