I have written a callback for a web service I am using. That service sends my web app a request and requires me to send a response within 3 seconds.
I call two methods from inside my doPost() method. What I want to do is to return the response after one of those methods has executed and then execute the second method.
Here is a sample of what I am trying to do -
protected void doGet(HttpServletRequest request, HttpServletResponse response)
throws ServletException, IOException {
PrintWriter writer = response.getWriter();
try {
this.doSomething();
writer.print("200 - OK");
writer.flush();
writer.close();
} catch (Exception e) {
writer.print("400 - Bad Request");
writer.flush();
writer.close();
}
this.doSomeThingElse();
}
Is this allowed? Or is the response sent after the doPost() method executes completely?
Also, under what condition does the thread that the servlet spawns to process the request get blocked? (i.e. it is not returned to the thread-pool)