小编Bry*_*son的帖子

基于每个上下文的 Tomcat 最大连接数

我有多个 Web 应用程序在单个 Tomcat 容器下运行。由于它们都在单个 Tomcat 连接器(如 server.xml 文件中定义)下运行,因此 maxConnections 和 maxThreads 等属性将容器作为一个整体进行管理。因此,单个应用程序可能会消耗所有可用的 Tomcat 线程,从而使其他线程应用程序处于饥饿状态并使其无响应。我希望能够在每个上下文的基础上定义最大的 http 线程,这样就不再可能了。

这是我迄今为止尝试过的:

  1. 在应用程序中创建一个自定义过滤器,以跟踪当前线程计数并限制其他连接。(这里有过滤器:如何设置 servlet 中并发请求数的限制?)。我不确定我是否喜欢这个解决方案,因为它不像 Tomcat 默认为容器提供的那样全功能(支持 acceptCount、maxConnections、maxThreads 和 minSpareThreads 等属性);并添加功能感觉就像我正在尝试构建 Tomcat 中已经存在的东西。
  2. 在 server.xml 文件中为每个上下文创建一个单独的 Tomcat 连接器。这有几个问题。一方面,每个连接器都需要一个单独的端口;这意味着我必须在我的 apache 配置中考虑到这一点。其次,我计划定期添加更多的webapps;这意味着配置更改后重启 tomcat,这对客户端来说是破坏性的。

有没有其他人遇到过这样的事情?我觉得应该有一个“支持 Tomcat”的工作流程来完成我所追求的工作。

java tomcat servlets

7
推荐指数
1
解决办法
2151
查看次数

使用ActiveMQ和Spring的JMS Standalone消费者

从历史上看,我已经将我的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)

我的问题:

  1. 我是否需要在主方法应用程序中执行任何特殊操作来关闭我的JMS连接,或者在应用程序终止时它们会关闭吗?
  2. 有没有人有任何个人偏好或其他关于是否使用tomcat或作为独立应用部署jms消费者?

编辑:

更多信息: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)

java spring tomcat activemq-classic

5
推荐指数
1
解决办法
3306
查看次数

Spring Security身份验证日志记录

我正在使用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)

logging spring log4j spring-security

4
推荐指数
2
解决办法
2万
查看次数