Skip to content

Instantly share code, notes, and snippets.

@maxant
Last active August 29, 2015 14:12
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save maxant/e9898335b1c20300ec22 to your computer and use it in GitHub Desktop.
Save maxant/e9898335b1c20300ec22 to your computer and use it in GitHub Desktop.
@WebServlet(urlPatterns = { "/AsyncServlet3" }, asyncSupported = true)
public class AsyncServlet3 extends HttpServlet {
@EJB private Service4 service;
protected void doGet(HttpServletRequest request, final HttpServletResponse response) throws ServletException, IOException {
...
final AsyncContext ctx = request.startAsync(request, response);
service.foo(s -> {
...
pw.write("</body></html>");
response.flushBuffer();
ctx.complete(); // all done, free resources
...
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment