• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Tim Cooke
  • Ron McLeod
  • paul wheaton
  • Jeanne Boyarsky
Sheriffs:
  • Paul Clapham
  • Devaka Cooray
Saloon Keepers:
  • Tim Holloway
  • Roland Mueller
  • Himai Minh
Bartenders:

Single Thread Model.

 
Ranch Hand
Posts: 393
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
What does Single Thread Model exactly mean?

Is it...only one thread/one instance at a time
or
is it...one thread/instance at a time...

I mean whenever a request comes, will the container create a new instance of the servlet? or will it create a thread & wait for the thread to complete b4 another request is taken up?
 
Ranch Hand
Posts: 57
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
 
Ranch Hand
Posts: 76
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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 !!!
 
Ranch Hand
Posts: 264
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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.


with thanks
 
Rancher
Posts: 43081
77
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

STM means that every servlet will have just one Instance and one thread at any point in time.


Is that really so? My understanding was that there can be multiple instances, each serving a single request -and thus being single-threaded-, just like Vandu said.
 
Ranch Hand
Posts: 245
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Single Thread Model simply means

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 ]
 
Sathish Nagappan
Ranch Hand
Posts: 76
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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 ]
 
Greenhorn
Posts: 22
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Is STM included in 310-081 ?
reply
    Bookmark Topic Watch Topic
  • New Topic