Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Are JAX-WS clients thread safe?

Tags:

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?

like image 498
PålOliver Avatar asked Dec 08 '10 07:12

PålOliver


People also ask

Is Jax RS client thread safe?

Either it's thread-safe in which case you would need only ONE instance in your application.

Is Resteasy client thread safe?

No, by default the ResteasyClient is not thread safe because of it's underlying HTTP dependencies.

Is CXF client thread safe?

Yes CXF is thread safe, you can use single instance/singleton for Weather and WeatherSoap, you can think of cxf as similar to servlet engine which handles all the infrastructure for you such as transport, databinding for you.

Is Jersey client thread safe?

Yes, the Jersey 2.1 client is thread safe and it should be thread safe even in the future Jersey version. You can create many WebTarget from one Client instance and invoke many requests on these WebTargets and even more requests on one WebTarget instance in the same time.


1 Answers

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.

like image 94
Daniel Kulp Avatar answered Oct 29 '22 21:10

Daniel Kulp