Asynchronous servlet

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();
..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset
3.146.221.144