aspose file tools*
The moose likes Servlets and the fly likes Requests to Servlets Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Soft Skills this week in the Jobs Discussion forum!
JavaRanch » Java Forums » Java » Servlets
Bookmark "Requests to Servlets" Watch "Requests to Servlets" New topic
Author

Requests to Servlets

Nupur Gupta
Ranch Hand

Joined: Aug 02, 2006
Posts: 45
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

Joined: Nov 24, 2005
Posts: 14688
    
  16

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.


[My Blog]
All roads lead to JavaRanch
Nupur Gupta
Ranch Hand

Joined: Aug 02, 2006
Posts: 45
Thanks a lot. For a particular servlet instance, is there a limit on the number of client requests it can face?
Christophe Verré
Sheriff

Joined: Nov 24, 2005
Posts: 14688
    
  16

I don't think that the servlet in itself has a particular limit.
Bear Bibeault
Author and ninkuma
Marshal

Joined: Jan 10, 2002
Posts: 61761
    
  67

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.


[Asking smart questions] [Bear's FrontMan] [About Bear] [Books by Bear]
Nupur Gupta
Ranch Hand

Joined: Aug 02, 2006
Posts: 45
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

Joined: Dec 11, 2004
Posts: 13410

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.


Java API J2EE API Servlet Spec JSP Spec How to ask a question... Simple Servlet Examples jsonf
Murari Baikady
Greenhorn

Joined: Apr 08, 2007
Posts: 1
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

Joined: Jan 10, 2002
Posts: 61761
    
  67

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.
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Requests to Servlets