Configure connections - Two web apps in the same Tomcat container
I am developing simultaneously two web applications that would be deployed in a Tomcat 6 container. My question is simple: Is it possible to configure or manage the number of connections (HTTP 开发者_StackOverflow社区requests) allowed by Tomcat to each application? Actually, I need a total number of connections which does not exceed 12, but I would like also to guarantee at least 4 connections for each application.
Thank you in advance
If you are looking to limit the maximum number of simultaneous connections then there is a Http Connector setting in Tomcat configuration called maxThreads. This defaults to 200 but you could set it to 12 in your case. See Tomcat Configuration Documentation.
If however you want to absolutely throttle the number of active sessions, as in a licensing restriction, you could keep an application scoped (servlet context) variable to add and substract as each session is created and destroyed, thus allowing you to validate any new sessions against this value and accept the session or present a nice message to the user if the quota is exceeded. You can use HttpSessionListener to monitor the creation and destruction of sessions. You could also use an Interceptor Pattern to perform the throttling functionality.
精彩评论