• 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 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

How SingleThreadModel servlet works

 
Ranch Hand
Posts: 47
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
 
Author and all-around good cowpoke
Posts: 13078
6
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
 
Rancher
Posts: 43081
77
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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.
 
Ranch Hand
Posts: 2308
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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.
reply
    Bookmark Topic Watch Topic
  • New Topic