• 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

Servlet Container

 
Greenhorn
Posts: 9
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi,
How does the Servlet Container handle multiple requests at a time?For instance
if you have a website and that website is accessed by 50 users.How does the Servlet container handle this situtation?

Thanks in Advance

GJ
 
Sheriff
Posts: 13411
Firefox Browser VI Editor Redhat
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
A new thread is created for each request.

The beginning of the servlet spec does a pretty good job of explaning this.
There is a link in my signature.
 
Ranch Hand
Posts: 672
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Is there a limitation as how many threads can be created at the same time?
Thanks
 
Ben Souther
Sheriff
Posts: 13411
Firefox Browser VI Editor Redhat
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
That depends on the container.
Here is the relevant Tomcat documentation.

http://jakarta.apache.org/tomcat/tomcat-5.5-doc/config/http.html
 
Ranch Hand
Posts: 5093
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
there is a limit. Each thread takes up memory and CPU resources and at some point those will run out.
But by the time you get to that point you're looking at many more reasons for buying more server hardware so it shouldn't be a problem.
 
Gregor Joseph
Greenhorn
Posts: 9
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Thanks for the solution.But I had a different question related to this.Does a Single Threaded Model help in preventing a Servlet from Handling Multiple requests at a time?

Thanks
GJ
 
Rancher
Posts: 13459
Android Eclipse IDE Ubuntu
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Nope, I believe that considering single thread model in this context is a mistake. STM ensures a servlet instance will only be accessed by a single thread at a time, but it does not say anything about the number of instances of this or any other servlet.
 
Ranch Hand
Posts: 208
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I believe the new version of servlet does not support single thread model. The web server accepts up to a limit number of http connnections. In this case, the number of servlet threads cannot exceed this limit.
 
Ranch Hand
Posts: 167
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Originally posted by Gregor Joseph:
Does a Single Threaded Model help in preventing a Servlet from Handling Multiple requests at a time?



Out of curiosity, why would you want to limit the number of concurrent requests to one? Or, for that matter, to any defined number?

If there is a strong business reason, I suppose you could implement it with a synchronized token in your servlet.
 
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
Limiting the number of concurrent requests can be handled in Tomcat with configuration parameters (see the link in Ben's post) - presumably other servlet containers have similar methods.
SingleThreadModel is still in the API as of 2.4 but is deprecated for very good reasons.
Bill
 
Sharad Agarwal
Ranch Hand
Posts: 167
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Originally posted by William Brogden:
Limiting the number of concurrent requests can be handled in Tomcat with configuration parameters (see the link in Ben's post) - presumably other servlet containers have similar methods.



To run off on a tangent, what is the general consensus on using non-standard container specific features? Does that not lead to vendor tie-in? Or is it that the add-on features are usually valuable enough that it is worth the loss in portability?
 
Greenhorn
Posts: 2
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
i think you whould vrify the link
 
Greenhorn
Posts: 11
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi,
this is vinay according to myself if the container get any request from the client it automatically starts a new thread but not new instance of the servlet. so the container manage the multiple requests like this
 
Ranch Hand
Posts: 472
Objective C Ubuntu Linux
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I've implemented single thread model in some servlet container. Actually it worked fine. Regarding number of concurrent threads, I believe socket backlog parameter will be actual limmitation.
 
Ben Souther
Sheriff
Posts: 13411
Firefox Browser VI Editor Redhat
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Originally posted by Sharad Agarwal:


To run off on a tangent, what is the general consensus on using non-standard container specific features? Does that not lead to vendor tie-in? Or is it that the add-on features are usually valuable enough that it is worth the loss in portability?



If this was a setting in web.xml that violated the spec or was 'extra-spec' I'd be dead set against it (Resin has a few of these). In this case, like JVM switches it has more to do with environmental issues and doesn't encourage apps to be written in a non-spec way that would limit their portability.

As Mr. Brogden stated, It's probably a common feature in other containers. I haven't used enough to say.
 
Sharad Agarwal
Ranch Hand
Posts: 167
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Originally posted by Ben Souther:


If this was a setting in web.xml that violated the spec or was 'extra-spec' I'd be dead set against it (Resin has a few of these). In this case, like JVM switches it has more to do with environmental issues and doesn't encourage apps to be written in a non-spec way that would limit their portability.

As Mr. Brogden stated, It's probably a common feature in other containers. I haven't used enough to say.



Thanks Ben. I like this neat delineation of what is acceptable and what is not.
 
With a little knowledge, a cast iron skillet is non-stick and lasts a lifetime.
reply
    Bookmark Topic Watch Topic
  • New Topic