Win a copy of Head First Agile this week in the Agile forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic

How SingleThreadModel servlet works  RSS feed

 
wrushasen dakhane
Ranch Hand
Posts: 47
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi,

When we implement the SingleThreadModel interface. For every request a new instance of the servlet gets created.

Consider for example if there any as many as 1000 requests then there would be 1000 instances running and which is not good.

Can anybody explain be how the web container handles the above situation?
Wrushu
 
William Brogden
Author and all-around good cowpoke
Rancher
Posts: 13078
6
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
The SingleThreadModel was created in the earliest servlet API because people had not yet figured out how best to keep the data for each user separate during a request. Basically it was a temporary expedient which was quickly abandoned as soon as people worked out better practices.

The ONLY reason it appears in the servlet API today is for backwards compatibility. If you think you need to use SingleThreadModel you need to take another look at your design.

Bill
 
Ulf Dittmer
Rancher
Posts: 42972
73
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Apart from what William said, keeping 1000 objects of anything should not be a big deal, assuming the servlet doesn't instantiate megabytes of instance data. Neither should handling 1000 requests, although most servers will keep the number of parallel worker threads to something lower than that, and let the other requests wait until a worker thread is available.
 
Rahul Bhattacharjee
Ranch Hand
Posts: 2308
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Its deprecated.

Moreover the container may choose to make one instance only but allowing only one request at a time.
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!