Win a copy of Think Java: How to Think Like a Computer Scientist this week in the Java in General forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Requests to Servlets

 
Nupur Gupta
Ranch Hand
Posts: 45
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi,
At a particular server, when a servlet is instantiated, do multiple clients access the same instance? Or is it recreated for each client? Maximum how many clients can access a particular servlet at one time? Can this be pre-defined?

Thanks a lot.
DG
 
Christophe Verré
Sheriff
Posts: 14691
16
Eclipse IDE Ubuntu VI Editor
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
For a servlet not hosted in a distributed environment (the default), the servlet container must use only one instance per servlet declaration. However, for a servlet implementing the SingleThreadModel interface, the servlet container may instantiate multiple instances to handle a heavy request load and serialize requests to a particular instance.
In the case where a servlet was deployed as part of an application marked in the deployment descriptor as distributable, a container may have only one instance per servlet declaration per Java Virtual Machine (JVMTM). However, if the servlet in a distributable application implements the SingleThreadModel interface, the container may instantiate multiple instances of that servlet in each JVM of the container.
 
Nupur Gupta
Ranch Hand
Posts: 45
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thanks a lot. For a particular servlet instance, is there a limit on the number of client requests it can face?
 
Christophe Verré
Sheriff
Posts: 14691
16
Eclipse IDE Ubuntu VI Editor
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I don't think that the servlet in itself has a particular limit.
 
Bear Bibeault
Author and ninkuma
Marshal
Pie
Posts: 64824
86
IntelliJ IDE Java jQuery Mac Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Originally posted by Nupur Gupta:
For a particular servlet instance, is there a limit on the number of client requests it can face?


No. And what would be the point? Either the servlet is multi-threaded or it's not. If a servlet can handle two simultaneous requests, it can handle any number. The limitation is on the number of threads a server can support.

And, SingleThreadModel is deprecated and should never be used.
 
Nupur Gupta
Ranch Hand
Posts: 45
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thanks a lot, Bear and Satou. Am requesting a clarification - so does a server have a pre-defined number of threads it can handle at a particular time? I guess this is like number of threads any machine can handle... perhaps threads just have to wait in queue until resources are available. But perhaps it can be pre-defined at the app server level.

Thanks a lot.
 
Ben Souther
Sheriff
Posts: 13411
Firefox Browser Redhat VI Editor
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Yes,
See the maxThreads attribute on this page (For Tomcat):
http://tomcat.apache.org/tomcat-5.5-doc/config/http.html

I'm not sure how other containers handle this.
 
Murari Baikady
Greenhorn
Posts: 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
The number of servlets the server can handle at one time is server dependent and most of the servers provide good performance. However i am not sure whether we can specify the number of servlets(threads) a server can handle in anyway. And the same servlet instance can be accessed by multiple requests(not matter what the number is) unless it implements the SingleThreadModel interface.
 
Bear Bibeault
Author and ninkuma
Marshal
Pie
Posts: 64824
86
IntelliJ IDE Java jQuery Mac Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Originally posted by Murari Baikady:
The number of servlets the server can handle at one time is server dependent and most of the servers provide good performance. However i am not sure whether we can specify the number of servlets(threads) a server can handle in anyway.


In the previous reply, it was shown how this can be done for Tomcat. Other servers may have similar settings.

And the same servlet instance can be accessed by multiple requests(not matter what the number is) unless it implements the SingleThreadModel interface.


Which, as was also pointed out in a previous reply, is deprected and should never be used.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic