Bookmark Topic Watch Topic
  • New Topic

Servlet Thread Model

 
maneesh subherwal
Ranch Hand
Posts: 42
  • Mark post as helpful
  • send pies
  • 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
 
Kem Bro
Greenhorn
Posts: 25
  • Mark post as helpful
  • send pies
  • 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 ]
 
Faisal Khan
Ranch Hand
Posts: 285
  • Mark post as helpful
  • send pies
  • 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
 
Michael Ernest
High Plains Drifter
Sheriff
Posts: 7292
Netbeans IDE VI Editor
  • Mark post as helpful
  • send pies
  • 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.
 
    Bookmark Topic Watch Topic
  • New Topic