Are JAX-WS clients thread safe?

依然范特西╮ 提交于 2019-11-27 01:49:45

问题


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?


回答1:


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.



来源:https://stackoverflow.com/questions/4385204/are-jax-ws-clients-thread-safe

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!