【问题标题】:Apache Axis2 and Spring ThreadApache Axis2 和 Spring 线程
【发布时间】:2011-10-13 04:12:21
【问题描述】:

好的,我正在使用 Apache Axis2 和 Spring Framework。基本上,WebServiceHandler 类是公开所有 Web 服务操作的类。所以当一个请求进来时,这是被调用的类。 我的理解是,对于每个请求,Tomcat 或 Axis2 都应该创建一个新线程。但是执行“Thread.currentThread().getId()”和“Thread.currentThread().getName()”总是具有相同的 id 和 name。

我认为这会导致我的 DAO 出现问题,因为我使用 Hibernate 创建 3 个 SessionFactories 并使用当前线程模型执行查询,这使得整个系统非常慢。

在调用我的 DAO 类之前,我可以为每个操作生成一个新线程,但还没有尝试过。有什么方法可以通过 Axis2 或 Spring 中的配置来解决这个问题?谢谢。

下面是我的 applicationContext.xml 的一部分:

<!-- Axis2 Web Service, but to Spring, its just another bean that has dependencies -->
<bean id="springContext" class="com.ws.beans.spring.SpringContext"/>

<bean id="springAwareService" class="com.ws.beans.WebServiceHandler" >
    <constructor-arg ref="springContext" />
</bean>

【问题讨论】:

    标签: web-services hibernate spring axis2 axis


    【解决方案1】:

    这是由 tomcat(或任何 web 容器)处理的。它不会为每个请求生成一个新线程,而是使用线程池来执行传入请求。在您的情况下,因为您一次只执行一个请求 - 相同的线程被用于执行后续请求。如果您尝试并行执行许多请求 - 那么您会注意到线程 ID/名称会有所不同。

    【讨论】:

    • 是的,谢谢,我想通了。我的问题是我在一个数据库表中有将近 200 万行。我不知道是什么导致了响应缓慢,所以调试时我认为这是 Tomcat 处理传入 HTTP 请求的方式。
    猜你喜欢
    • 1970-01-01
    • 2012-07-07
    • 1970-01-01
    • 2017-05-07
    • 2011-12-05
    • 2015-08-31
    • 2011-04-03
    • 1970-01-01
    • 2013-06-29
    相关资源
    最近更新 更多