• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

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

 
Sanjay Ra
Ranch Hand
Posts: 31
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 5093
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
 
William Brogden
Author and all-around good cowpoke
Rancher
Posts: 13058
6
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 580
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
You could also do it yourself using some form of a semaphore in your servlet.
 
Sanjay Ra
Ranch Hand
Posts: 31
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 580
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 580
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
You could also use a servlet filter...
 
Sanjay Ra
Ranch Hand
Posts: 31
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
thanks!
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic