Win a copy of The Java Performance Companion this week in the Performance forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Single Threaded Model Question

 
riya s
Ranch Hand
Posts: 110
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
The specification guarantees that the servlet implements the SingleThreadModel the container will not execute the service method with more than one thread.
When we implement this model we assume that when we define the instance variables they are thread safe (just like the local variables)
Question is: Why the above? In JSP when we define instance variables using declaration, they are not part of the service method. So instance variables are not part of service and the model guarantees the container will not execute the service method with more than one thread...
Any idea?
 
Sean Joung
Greenhorn
Posts: 4
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
FYI SingleThreadModel is out of Servlet2.4
 
Jayadev Pulaparty
Ranch Hand
Posts: 662
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Originally posted by Priya Shah:

When we implement this model we assume that when we define the instance variables they are thread safe (just like the local variables)
Any idea?

We donot assume that the instance variables are thread safe, but they are in fact as the container provides every request with a separate servlet instance.
Originally posted by Priya Shah:

Question is: Why the above? In JSP when we define instance variables using declaration, they are not part of the service method. So instance variables are not part of service and the model guarantees the container will not execute the service method with more than one thread...
Any idea?

I think service method has no knowledge of the instance variables in your servlet class (or the jsp that ultimately turns into a servlet). When it comes to servlets, we derice from the HttpServlet and override the doGet and doPost methods. The service method just routes the appropriate HTTP requests to the methods in the object. I'm a little confused with you mixing the instance variables with the service method.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic