Apache Axis2 和 Spring 线程
好的,我正在使用 Apache Axis2 和 Spring 框架。基本上,WebServiceHandler 类是公开所有 Web 服务操作的类。因此,当请求到来时,这个类就会被调用。 我的理解是,对于每个请求,Tomcat 或 Axis2 都应该创建一个新线程。但是执行“Thread.currentThread().getId()”和“Thread.currentThread().getName()”总是具有相同的id和名称。
我相信这会导致我的 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>
Ok I'm using Apache Axis2 and Spring Framework. Basically The WebServiceHandler class is the one that exposed all the web service operations. So when a request comes in, this is the class that gets called.
My understanding is that for every request, Tomcat or Axis2 should create a new Thread. But doing a "Thread.currentThread().getId()" and "Thread.currentThread().getName()" always have same id and name.
This I believe causes problems on my DAO since I'm using Hibernate to create 3 SessionFactories and using the current thread model to execute queries, which makes whole system really slow.
I could spawn a new Thread for every operation before calling my DAO class but haven't tried that yet. Any way to solve this through configuration in Axis2 or Spring? Thanks.
Part of my applicationContext.xml below:
<!-- 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 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
这是由 tomcat(或任何 Web 容器)处理的。它不会为每个请求生成一个新线程,而是使用线程池来执行传入的请求。在您的情况下,由于您一次仅执行一个请求 - 同一线程用于执行后续请求。如果您尝试并行执行多个请求 - 那么您会注意到线程 ID/名称会有所不同。
This is handled by tomcat (or any web container). It doesn't spawn a new thread for every request - but instead uses a thread pool to execute the incoming request. In your case since you are only executing one request at a time - the same thread is being used to execute subsequent requests. If you try executing many requests in parallel - then you will notice that the thread ids / names will be different.