Asynchronous processing

There are common scenarios in enterprise applications that are usually synchronous and blocking, for example, database or remote server calls. In those cases, the call at these methods takes some time to return, usually with a client thread that is blocked waiting for the answer. Let's consider a simple example—a Java EE servlet that queries a database, using a service, and prints the list of the records, in our case a list of authors (yes, I know, I'm a little bit egocentric):

@WebServlet(urlPatterns = "/authors")public class AuthorServlet extends HttpServlet {    ...    @Override    protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws           ServletException, IOException { final List<Author> authors = authorService.getAuthors(); ...

Get Hands-On Cloud-Native Microservices with Jakarta EE 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.