配置连接 - 同一 Tomcat 容器中的两个 Web 应用程序
我正在同时开发两个将部署在 Tomcat 6 容器中的 Web 应用程序。 我的问题很简单:是否可以配置或管理 Tomcat 允许的每个应用程序的连接(HTTP 请求)数量? 实际上,我需要的连接总数不超过12,但我还想保证每个应用程序至少有4个连接。
先感谢您
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 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
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
如果您希望限制同时连接的最大数量,那么 Tomcat 配置中有一个名为 maxThreads 的 Http 连接器设置。默认值为 200,但您可以根据您的情况将其设置为 12。请参阅 Tomcat 配置文档。
但是,如果您想绝对限制活动会话的数量,如在许可限制中,您可以保留一个应用程序范围(Servlet 上下文)变量,以便在创建和销毁每个会话时进行添加和减去,从而允许您验证任何新会话根据此值并接受会话或在超出配额时向用户显示一条友好消息。您可以使用 HttpSessionListener 来监视创建和会话的破坏。您还可以使用拦截器模式来执行限制功能。
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.