I am making a restful call to the servlet doGet()
method. Inside the doGet()
method I am making a method call which takes a lot of time for processing due to which the doGet()
method times out and cannot send a response back to the application which made the call.
So now I want to send a response back to the application which called the doGet()
method immediately the doGet()
is invoked.
Can I use Threads like one thread will reply back and the other one will continue with the method invocation. Do i need to use any webservice
frame work like Jersey
?
protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
// TODO Auto-generated method stub
System.out.println("in the Do Get");
String tableName = (String)request.getParameter("tableName");
tableName = tableName.replaceAll("[^A-Z0-9_]", "");
System.out.println("setup connections");
SampleService sampleService = new SampleService(new Properties());
Thread t = new Thread(new Runnable() {
public void run() {
// stuff here
sampleService.execute(tableName);
}
});
t.start();
i am making the class to implement the Runnable interface and writing the logic of the method call(the method which takes lot of time to process) inside the run method. Also how to send a response while this one is running