Let's split our AsyncServlet class into pieces so we can understand it:
@WebServlet(urlPatterns = "/AsyncServlet", asyncSupported = true)
Here, we defined our servlet for accepting async behavior by using the asyncSupported param:
AsyncContext asyncCtx = request.startAsync();
We used the request being processed to start a new async context.
Then we start our async process:
asyncCtx.start(() -> {...
And here we print our output to see the response and finish the async process:
asyncCtx.getResponse().getWriter().write("Async
process time: "
+ timeElapsed + " milliseconds");
asyncCtx.complete();