我有多个 Web 应用程序在单个 Tomcat 容器下运行。由于它们都在单个 Tomcat 连接器(如 server.xml 文件中定义)下运行,因此 maxConnections 和 maxThreads 等属性将容器作为一个整体进行管理。因此,单个应用程序可能会消耗所有可用的 Tomcat 线程,从而使其他线程应用程序处于饥饿状态并使其无响应。我希望能够在每个上下文的基础上定义最大的 http 线程,这样就不再可能了。
这是我迄今为止尝试过的:
有没有其他人遇到过这样的事情?我觉得应该有一个“支持 Tomcat”的工作流程来完成我所追求的工作。
从历史上看,我已经将我的JMS使用者应用程序部署为在Tomcat(Windows框)下部署的Spring webapps.然后,这些消费者将在同一个Tomcat实例下与我的其他Web应用程序一起运行.然而,随着我使用的消费者数量的增长,我意识到这将成为一种维护噩梦.
我的解决方案是将这些webapps转换为部署为jar的"main method"独立应用程序.实际上,我能够成功地将它们打包在一起,以尝试尽可能多地重用资源(DAO,依赖项等).
这是我的主要方法:
public static void main(String[] args) {
ApplicationContext context = new ClassPathXmlApplicationContext("applicationContext.xml");
try {
FooListener fooListener = (FooListener) context.getBean("fooListener");
fooListener.start();
} catch (Exception e) {
logger.error(e.getMessage(), e);
}
try {
BarListener barListener = (BarListener) context.getBean("barListener");
barListener.start();
} catch (Exception e) {
logger.error(e.getMessage(), e);
}
}
Run Code Online (Sandbox Code Playgroud)
我的问题:
编辑:
更多信息:FooListener和BarListener扩展了以下抽象类.它们从applicationContext.xml文件中的相应bean继承它们的值,并且它们都覆盖onMessage()方法以异步使用消息.
public abstract class TextMessageListener implements MessageListener {
protected ConnectionFactory connectionFactory;
protected String queueName;
protected String selectors;
public void start() throws JMSException {
Connection connection = connectionFactory.createConnection(); …Run Code Online (Sandbox Code Playgroud) 我正在使用Spring Security 3.1来验证网站的用户.当登录失败,因为spring安全性无法连接到数据库时,我在日志中收到以下语句:
2012-07-12 11:42:45,419 [ajp-bio-8009-exec-1] DEBUG org.springframework.security.web.authentication.UsernamePasswordAuthenticationFilter - Authentication request failed: org.springframework.security.authentication.AuthenticationServiceException: Could not get JDBC Connection; nested exception is java.sql.SQLException: Connections could not be acquired from the underlying database!
Run Code Online (Sandbox Code Playgroud)
我的问题是,为什么这是一个DEBUG语句而不是ERROR?我必须浏览大量的调试语句才能找到实际的错误.
编辑
这是我的身份验证管理器:
<bean id="securityDataSource" class="org.springframework.jndi.JndiObjectFactoryBean">
<property name="jndiName" value="java:comp/env/securityDS"/>
<property name="resourceRef" value="true"/>
</bean>
<bean id="encoder" class="org.springframework.security.crypto.password.StandardPasswordEncoder" />
<security:authentication-manager>
<security:authentication-provider>
<security:password-encoder ref="encoder" />
<security:jdbc-user-service
data-source-ref="securityDataSource"
authorities-by-username-query="SELECT username, authority FROM login WHERE username = ?"
users-by-username-query="SELECT username, password, enabled FROM login WHERE username = ?"
/>
</security:authentication-provider>
</security:authentication-manager>
Run Code Online (Sandbox Code Playgroud)