For an object to be runnable, it needs to implement the Runnable interface or extend the Thread class, however, it does not seem that HttpServlet does any of these.
How come HttpServlet can be threaded or have i mistaken?
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.
The Servlet itself is not a thread. The container maintains one instance of the servlet class and each request (thread) calls the same servlet object. So the servlet instances is shared across threads. In pseudo code it may look like this:
No question, in reality it will be much, much, much more complex 🙂
BTW: That’s the reason your servlet classes have to be thread safe!