Is there anyway to configure tomcat to reserve threads to a specific servlet or webservice? I understand this could probably be done programatically in a servlet filter.
So suppose I go with the default configuration of 250 serving threads, but I want 20 of them to be reserved for a specific servlet/webservice?
Maybe this is obviously impossible - if so could someone please explain why?
Im using tomcat 6.
It's not possible per the servlet specification. However in Tomcat you can define several connectors running on different ports. Each connector has a separate thread pool:
<Connector port="8081" protocol="HTTP/1.1"
connectionTimeout="20000"
redirectPort="10443" />
You'll find examples of how to configure thread pools in server.xml
file undere /conf
directory in Tomcat.
Now you can access your web applications using both 8080 (default) and 8081 (configured above). Requests through 8081 will use a different thread pool. All you have to do now is route all servlets through 8080 and your specific thread through 8081 (using completely independent thread pool).
If you don't want someone to abuse this, add a servlet filter to check whether correct port is used based on requested URI.
However reading your rationale:
I have a specific synchronous service that locks up a lot of the serving threads
You'll better start and manage your own pool of threads (check out ExecutorService
) and use asynchronous servlet. Much simpler and portable.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With