Win a copy of 97 Things Every Java Programmer Should Know this week in the Java in General forum!
  • 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 all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Paul Clapham
  • Jeanne Boyarsky
  • Junilu Lacar
  • Henry Wong
Sheriffs:
  • Ron McLeod
  • Devaka Cooray
  • Tim Cooke
Saloon Keepers:
  • Tim Moores
  • Stephan van Hulst
  • Frits Walraven
  • Tim Holloway
  • Carey Brown
Bartenders:
  • Piet Souris
  • salvin francis
  • fred rosenberger

java - single thread model

 
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?
 
Ranch Hand
Posts: 5575
Eclipse IDE Windows XP Java
  • 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
 
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.
 
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.
 
Could you hold this puppy for a sec? I need to adjust this tiny ad:
Devious Experiments for a Truly Passive Greenhouse!
https://www.kickstarter.com/projects/paulwheaton/greenhouse-1
    Bookmark Topic Watch Topic
  • New Topic