The JAX-RS client API supports asynchronous request processing. By default, invocations are synchronous but can be set to run asynchronously by calling the Invocation.Builder.async() method and registering an instance of InvocationCallback.
Example
A resource with async processing
@Path("/orders")
public class OrderResource {
@GET
public void getAllOrders(@Suspended final AsyncResponse ar) {
ExecutorService es = Executors.newSingleThreadExecutor();
es.submit(() -> {
try {
//Simulating a long running process
Thread.sleep(2000);
} catch (InterruptedException e) {
e.printStackTrace();
}
ar.resume("all orders data....");
es.shutdown();
});
}
}