Are JAX-WS clients thread safe?
Asked Answered
P

1

21

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?

Philina answered 8/12, 2010 at 7:42 Comment(1)
This is not clear from specs. Check this for example:community.jboss.org/message/526321Aulea
B
16

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.

Brinkema answered 8/12, 2010 at 12:38 Comment(3)
Thanks Daniel, that was my suspicion too, but do you have any official reference that confirms this?Allamerican
Look like an old thing...but very actual for me.@Daniel what do you mean by clean the set values...I am interested in that cause i asked this without too much success :#6883028Lambertson
For JAX-WS/Metro that's definitely thread safe since a very very long time.Ivett

© 2022 - 2024 — McMap. All rights reserved.