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
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

Servlet Thread Model

 
Ranch Hand
Posts: 42
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Report post to moderator
All,
I have a question that folks here at JavaRanch may be familiar.
Could someone please explain servlet instantiations (probably in Tomcat) using a Single Threaded Model versus Multi-Threaded Model?
My confusion basically refers to this:
If I have servletA requested at the same time by two different requests, what happens? Does a new instance of the servlet get initiated for each request? If not, how is it synchronized?
Thank you.
cyberCipher
 
Greenhorn
Posts: 25
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Report post to moderator
Hi,
To the best of my knowledge if an object is already instantiated the container will use that one to service the request. If the servlet/jsp is flagged as being thread safe, the container creates a new object if there already is an object of that type servicing another request.
The container manages synchronisation once the jsp/servlet are flagged as thread safe.
I think that's how it works anyway, maybe someone else can put more light on this.
Kem Bro
[ September 04, 2003: Message edited by: Kem Bro ]
 
Ranch Hand
Posts: 285
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Report post to moderator
Single Thread Model means that for each request a new instance of the servlet has to be instantiated, therefore making it very inefficient and slow. Especially so if the requests are served sequentially (depends on the servlet container).
Normally there is only one instance of the Servlet and a new thread is issued for each new request. Thus the request scope variables are thread safe.
HTH
 
High Plains Drifter
Posts: 7289
Netbeans IDE VI Editor
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Report post to moderator
This appears to have been cross-posted in the Servlets forum. Since it seems more appropriate there, I'm closing this one.
 
Consider Paul's rocket mass heater.
    Bookmark Topic Watch Topic
  • New Topic