简体   繁体   English

JAX-WS Web服务线程模型

[英]JAX-WS web services threading model

(1) Okay I am pretty confused about the threading model of JAX-WS Java web services. (1)好的,我对JAX-WS Java Web服务的线程模型非常困惑。 I read they are not thread-safe. 我读过它们不是线程安全的。 How are they supposed to serve multiple parallel requests then? 他们应该如何服务多个并行请求呢? Given that its always known (mostly) they are going to get called from multiple clients at the same time. 鉴于它总是已知(大部分),它们将同时从多个客户端调用。

(2) And does the app server create a new instance of web service for each request (like it maintains a pool of stateless session beans, assigns one out for a request and once the request completes, it is returned to the pool). (2)app服务器是否为每个请求创建一个新的Web服务实例(就像它维护一个无状态会话bean池,为一个请求分配一个,一旦请求完成,它就返回到池中)。 can you configure that pool size in app server console (GlassFish or JBoss or WebSphere). 您可以在应用服务器控制台(GlassFish或JBoss或WebSphere)中配置该池大小。

(3) And I also found out about @Threadsope annotation here which creates new thread per request.. (3)我还在这里发现了@Threadsope注释,它为每个请求创建了新的线程。
http://jax-ws-commons.java.net/thread-scope/ http://jax-ws-commons.java.net/thread-scope/
Is that a good option? 这是一个不错的选择吗? I am sure people are solving the thread-safety and parallel requests issues in some other standard way - please advise. 我相信人们正在以其他标准方式解决线程安全和并行请求问题 - 请提供建议。

An application server contains a pool of beans. 应用程序服务器包含一个bean池。
When working with stateless session bean, it is not guaranteed you will get the same instance across working with the session. 使用无状态会话bean时,无法保证在使用会话时获得相同的实例。
However, since as I mentioned, the beans are managed by a pool, holding a state in them, is a bad idea. 但是,正如我所提到的那样,bean由一个池管理,在其中保存一个状态,这是一个坏主意。
I don't think that EJB beans have anything to do with what your need, though. 但是,我不认为EJB bean与您的需求有任何关系。
Pay attention that in the example you provided, Both DataService and the connection are created per request. 请注意,在您提供的示例中,每个请求都会创建DataService和连接。 This is a bit expensive. 这有点贵。
I would consider using the ThreadLocal API only for the connection, and have it obtained from a connection pool. 我会考虑仅将ThreadLocal API用于连接,并从连接池获取它。
You can implement these on your own, by reading about ThreadLocal and by reading about DB connection pools. 您可以通过阅读ThreadLocal和阅读有关数据库连接池的信息来实现这些功能


To conclude - I don't think EJBs are relevant here. 总而言之 - 我不认为EJB在这里是相关的。
Don't hold both your service class and the fields at the thread local, but only the necessary fields you will allocate per request. 不要将服务类和字段保存在本地线程中,而只保留每个请求将分配的必要字段。 (in the example you showed - it's the connection) (在你展示的例子中 - 这是连接)

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM