-1

I'll explain my task: I have to make a servlet where from jsp it get the process request, returns 200 to the jsp, than the jsp needs to check every n if my servlet ended the job

Here what I tried to do:

   @WebServlet(name = "ProcessServlet", urlPatterns = {"/ProcessServlet"}, asyncSupported = true)
    @MultipartConfig
    @SessionScoped
    public class ProcessServlet extends HttpServlet {
@Override
    public void doGet(HttpServletRequest request, HttpServletResponse response) throws IOException {

        final AsyncContext asyncContext = request.startAsync();
 asyncContext.start(() -> {
                    process(response, year, user);
                    HttpServletResponse asyncResponse = (HttpServletResponse) asyncContext.getResponse();
                    asyncResponse.setStatus(HttpServletResponse.SC_OK);
                    try {
                        asyncResponse.getWriter().write("completed");
                    } catch (IOException e) {
                        throw new RuntimeException(e);
                    }
                    asyncContext.complete();
                });
}

as you can see I tried to retrun 200 than start my process (it will take time to complete) and than get the completed status but when I try I just have to wait the whole process and i got both responses, any idea what should i do from here to end this task???

Thanks a lot to all

BalusC
  • 1,082,665
  • 372
  • 3,610
  • 3,555
Alex
  • 85
  • 6

0 Answers0