Issue
HttpServletRequest request;
HttpServletResponse response;
public void doGet(HttpServletRequest request , HttpServlet response){
this.request = request;
this.response = response;
}
What happens if this servlet receives multiple requests at a time?
We faced a response mismatch issue. Is this an issue?
Solution
Its an issue and it is never advisable to declare HttpServletRequest request/HttpServletResponse response as an instance variable. Actually Servlet is implementing single thread model that means only one servlet instance is created. And one thread for each request. So if their are many requests then thr must be many threads and each sharing same servlet instance inturn it will create data mismatch or data inconsistency problem. Threads will work on the same instances.
Answered By - Brijesh
Answer Checked By - Cary Denson (JavaFixing Admin)