Single threaded model means single thread multiple instances .....because the main thing in the single thread model is not to support multiple threads....hence single thread....inorder to support multiple requests it may use multiple instances .......Hope it helps to some extent
To put in a different way , STM means that every servlet will have just one Instance and one thread at any point in time. That is how it guarantees Thread Safety for the instance variables of the servlet , but request attributes and session attributes and Servlet Context attributes are not safe because they can be used by JSPs too and other Servlets (even if the other Servlets Implement STM , they still have access to the attribute). Besides due to this you cannot have multiple instances of a servlet running in the same JVM (even as heavy weight processes) and hence the webserver cannot service multiple clients simultaneously.
The bottom line is : DO NOT USE STM !!!
SCJP, SCWCD, SCBCD, IBM XML, IBM OOAD, SCEA 5, ITAC - Distinguished IT Architect.
Fernado, Does this implies that there can be maximum of one request for the STM servlet at a time?.Becaz we can't have mutiple threads and even mutiple instances for a STM servlet.then how does the container handles when there are more than one request for STM servlet is coming concurrently.
when you really want something, all the universe always conspires in your favour.<br /> <br />SCJP1.5-77%<br />SCWCD-89%
ONLY ONE THREAD running on ONE instance of a servlet
This can be implemented in many ways
1) Servlet container creates only one instance of the servlet. This way only one request for servlet can be serviced at a time
2) To improve performance, sometimes servlet container will create a pool of servlet instances . Only one thread will be running on one of the servlet instances at a given point of time
Thus, we cannot be sure that even instance variables are thread safe in STM
And request attributes are thread safe,because a request object is only being processed by only one thread at any given instance of time... [ June 28, 2006: Message edited by: Vivek Pandey ]
Joined: Nov 05, 2005
I dont think so, The Head First JSP and Servlets book says that , if you are using STM or isThreadSafe in your JSP , then you are kissing your concurrency goodbye. Now if there were multiple instances of a servlet ,each having a single thread just as you (Vandu and Ulf) said, then you can still have concurrent requests , only thing is the overhead that for each servlet the container creates multiple objects which consumes space on the RAM like EJB's. Hence you have multiple instances and instance variables become thread safe. But all the other variable scopes are not. ServletContext , HttpServletRequest and HttpSession , cos it can pass through other Web components and are not limited to servlets.
Either the HFSJ book's 'you are kissing your concurrency goodbye and STM brings a web server to its knees cos it can only service a single client at a time' is wrong or That is container/vendor dependent. [ July 03, 2006: Message edited by: ashwanth fernando ]