• 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

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

 
Ranch Hand
Posts: 31
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
 
Ranch Hand
Posts: 5093
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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.
 
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 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
 
Ranch Hand
Posts: 580
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
You could also use a servlet filter...
 
Sanjay Ra
Ranch Hand
Posts: 31
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
thanks!
reply
    Bookmark Topic Watch Topic
  • New Topic