JAX-WS 客户端线程安全吗?

发布于 2024-10-06 06:29:38 字数 811 浏览 0 评论 0原文

因为 WS 客户端端口的初始化成本非常高,所以我们希望重用同一个实例。我们还希望在每次调用之前在 BindingProvider/RequestContext 中设置不同的值。最初我们想这样做:

MyService service = new MyService(wsdlURL, name); 
MyPort myPort = service .getMyServicePort(); 

然后,在每次调用之前执行以下操作:

Map requestContext = ((BindingProvider)myPort ).getRequestContext(); 
requestContext.put(BindingProvider.USERNAME_PROPERTY, uName); 
requestContext.put(BindingProvider.PASSWORD_PROPERTY, pWord); 
myPort.someFunctionCall();

我的问题是,这段代码线程安全吗? JAX-WS 文档似乎表明它不是线程安全的。但是,如果您采取预防措施,CXF 似乎就是这样。如果 JAX-WS 和 Metro 尤其不是线程安全的,是否有任何方法可以在不同步访问的情况下确保线程安全到港口还是ws操作?

Because the initialization of the WS client side port is so costly we would like to reuse the same instance. We would also like to set different values in the BindingProvider/RequestContext before each call. Initially we would like to do this:

MyService service = new MyService(wsdlURL, name); 
MyPort myPort = service .getMyServicePort(); 

then later, before each call do this:

Map requestContext = ((BindingProvider)myPort ).getRequestContext(); 
requestContext.put(BindingProvider.USERNAME_PROPERTY, uName); 
requestContext.put(BindingProvider.PASSWORD_PROPERTY, pWord); 
myPort.someFunctionCall();

My question is, is this code thread safe? JAX-WS documentation seems to indicate that it is not thread safe. However, CXF seems to be so if you take precautions. If JAX-WS and Metro in particular is not thread safe, is there any way of ensuring thread safety without synchronizing access to port or ws operations?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

那伤。 2024-10-13 06:29:38

对于 JAX-WS/Metro,这绝对不是线程安全的。最好的办法是创建一个代理池,并在需要时从池中提取代理,配置它,使用它,清除设置值,然后返回池。

或者使用CXF。

For JAX-WS/Metro, that's definitely not thread safe. The best bet is to create a Pool of proxies and, when needed, pull a proxy from the pool, configure it, use it, clear the set values, return to the pool.

Or use CXF.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文