Are there multiple instances of servlet class? As I hear “each instance of servlet”
Can anybody elaborate on this?
Are there multiple instances of servlet class? As I hear each instance of servlet
Share
Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.
Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.
Lost your password? Please enter your email address. You will receive a link and will create a new password via email.
Please briefly explain why you feel this question should be reported.
Please briefly explain why you feel this answer should be reported.
Please briefly explain why you feel this user should be reported.
When the Servlet container starts, it:
web.xml;Roughly, like this:
Those Servlets are stored in memory and reused every time the request URL matches the Servlet’s associated
url-pattern. The servlet container then executes code similar to:The
GenericServlet#service()on its turn decides which of thedoGet(),doPost(), etc.. to invoke based onHttpServletRequest#getMethod().You see, the servletcontainer reuses the same servlet instance for every request. In other words: the servlets are shared among every request. That’s why it’s extremely important to write servlet code the threadsafe manner –which is actually simple: just do not assign request or session scoped data as servlet instance variables, but just as method local variables. E.g.