Here I am going to give an example on how Asynchronous REST webservice with Timeout works.
The most important concept in REST is resources, which are identified by global IDs — typically using URIs. Client applications use HTTP methods (GET/ POST/ PUT/ DELETE) to manipulate the resource or collection of resources. A RESTful Web service is implemented using HTTP and the principles of REST. Typically, a RESTful Web service should define the following aspects:
The base/root URI for the Web service such as http://<host>/<appcontext/contextpath>/<url pattern>/<resources>.
The MIME type of the response data supported, which are JSON/XML/TEXT/HTML etc.
The set of operations supported by the service. (for example, POST, GET, PUT or DELETE).
HTTP methods are mapped to CRUD (create, read, update and delete) actions for a resource. Although you can make slight modifications such as making the PUT method to be create or update, the basic patterns are listed as follows.
HTTP GET: Get/List/Retrieve an individual resource or a collection of resources.
HTTP POST: Create a new resource or resources.
HTTP PUT: Update an existing resource or collection of resources.
HTTP DELETE: Delete a resource or collection of resources.
Eclipse, JDK 1.6
For more information on Asynchronous Service please go through https://jersey.java.net/documentation/latest/async.html
Asynchronous Server API
By default client connection of a request is processed in a synchronous mode in server in a single I/O container thread. After processing the client request, the thread returns to the I/O container and I/O container safely assumes that the request process is finished. Thus all resources associated with the client connection are released. This kind of synchronous mechanism is sufficient for requests which take relatively short execution time. But for requests which take relatively longer execution time, the association between a request processing thread and client connection is broken. Thus server-side asynchronous processing model should be used to facilitate explicitly suspend, resume and close the client connections.
Now I will go to the coding part and below steps to be followed to create an asynchronous REST servive. We will use grizlly web server for running the service. Read More