JAX-WS 客户端线程安全吗? [英] Are JAX-WS clients thread safe?

查看:29
本文介绍了JAX-WS 客户端线程安全吗?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

由于 WS 客户端端口的初始化成本很高,我们希望重用相同的实例.我们还想在每次调用之前在 BindingProvider/RequestContext 中设置不同的值.最初我们想这样做:

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();

我的问题是,这段代码线程安全吗?JAX-WS 文档似乎表明它线程安全.但是,CXF 似乎是这样,如果您采取预防措施.如果 JAX-WS 和 Metro 特别不是线程安全的,有没有办法在不同步访问的情况下确保线程安全移植或 ws 操作?

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?

推荐答案

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

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.

或者使用 CXF.

这篇关于JAX-WS 客户端线程安全吗?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆