• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

java - single thread model

 
rinita de
Greenhorn
Posts: 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
In STM when a new request comes a new instance of servlet is created. Are these instances created concurrently? Or at a time only one instance is present?
 
Seetharaman Venkatasamy
Ranch Hand
Posts: 5575
Eclipse IDE Java Windows XP
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Originally posted by rinita de:
In STM when a new request comes a new instance of servlet is created. Are these instances created concurrently?


it wont be concurrently . correct me,if i am wrong
 
Rufus Addis
Ranch Hand
Posts: 83
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Firstly the Single Thread Model is deprecated in the Servlet API spec 2.4 and as far as I know no longer an objective in the latest SCWCD exam.

In answer to your question I believe that there is nothing in the specs which specify whether the servlets are created concurrently or not, it's up to the container implementation. The container has to ensure that no two threads share the same instance of the servlet. It is not uncommon to create a number (pool) of servlet instances [concurrently], then make instances of the serlet available from that pool to threads under the STM.

However I would urge you purge the Single Thread Model from your brain as it has no place in a Java developers mind!

Rufus.
 
praveena reddyk
Greenhorn
Posts: 11
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi,
SingleThreadModel ensures that servlets handle only one request at a time .In SingleThreadModel, it is guaranteed that no two threads will execute concurrently in the servlet's service method.

There are two ways of implementing SingleThreadModel:

1.The servlet container synchronizes access to a single instance of the servlet, i.e there is only single instance of servlet which process every incoming request.
2. container maintaines a pool of servlet instances and dispatches each new request to a free servlet.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic