Using an asynchronous method to create a background process
Accessing an EJB synchronously allows the client to continue its work without having to wait for the EJB to return. This can be used in one of two ways. The first technique is done in an "invoke and forget" manner where the request is made of the EJB and the client is not concerned about the success or failure of the request. The second technique invokes the method but does not wait for the method to complete. The method returns a
Future object. This object is used later to determine the result of the request.
In this recipe, we will develop a stateless
PrintServlet EJB with two methods:
printAndCheckLater, used to demonstrate the use of asynchronous methods.