my dog learned polymorphism*
The moose likes Servlets and the fly likes Can i set the no of threads per servlet in web.xml? Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Murach's Java Servlets and JSP this week in the Servlets forum!
JavaRanch » Java Forums » Java » Servlets
Bookmark "Can i set the no of threads per servlet in web.xml?" Watch "Can i set the no of threads per servlet in web.xml?" New topic
Author

Can i set the no of threads per servlet in web.xml?

Sanjay Ra
Ranch Hand

Joined: Nov 05, 2004
Posts: 31
hi,

Is there a way to set the no of threads of the web container(tomcat) to allocate a fixed no of threads on a per servlet basis in say the web.xml or any other way?

thanks
Sanjay
Jeroen Wenting
Ranch Hand

Joined: Oct 12, 2000
Posts: 5093
no.
A servlet container will launch at most one instance of every servlet defined in the web.xml and will thereafter create a single thread for each concurrent request to that servlet.


42
William Brogden
Author and all-around good cowpoke
Rancher

Joined: Mar 22, 2000
Posts: 12760
    
    5
Limiting the number of Thread is possible but it is not part of the servlet API and web.xml. With the Tomcat server, look at the server.xml file entry:

It is up to each server architect to provide for limiting simultaneous request processing Threads. In this case it is the whole port 80 Connector that is limited, not the individual servlet. If you want to control the number of requests per servlet you will have to write your own code.
Bill
James Carman
Ranch Hand

Joined: Feb 20, 2001
Posts: 580
You could also do it yourself using some form of a semaphore in your servlet.


James Carman, President<br />Carman Consulting, Inc.
Sanjay Ra
Ranch Hand

Joined: Nov 05, 2004
Posts: 31
Hi Guys,

thanks for the response ..is there an example of this servlet code where i can limit the threads?


thanks
Sanjay
James Carman
Ranch Hand

Joined: Feb 20, 2001
Posts: 580
If you're using JDK 5, you can use the java.util.concurrent.Semaphore class...



If you're not using JDK 5, you can download the equivalent (more or less) classes from Doug Lea's website.
James Carman
Ranch Hand

Joined: Feb 20, 2001
Posts: 580
You could also use a servlet filter...
Sanjay Ra
Ranch Hand

Joined: Nov 05, 2004
Posts: 31
thanks!
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Can i set the no of threads per servlet in web.xml?
 
Similar Threads
Status 404 error coming up while making the servlet app run on the tomcat server
Nubmer of servlet instance
session
web.xml in distributed env.
Servlet instances and its init method