title: Are JAX-WS clients thread safe?
body: <p>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:</p>
  
  <pre><code>MyService service = new MyService(wsdlURL, name); 
  MyPort myPort = service .getMyServicePort(); 
  </code></pre>
  
  <p>then later, before each call do this:</p>
  
  <pre><code>Map requestContext = ((BindingProvider)myPort ).getRequestContext(); 
  requestContext.put(BindingProvider.USERNAME_PROPERTY, uName); 
  requestContext.put(BindingProvider.PASSWORD_PROPERTY, pWord); 
  myPort.someFunctionCall();
  </code></pre>
  
  <p>My question is, is this code thread safe? JAX-WS documentation seems to indicate that it is <strong>not</strong> thread safe. However, <a href="http://cxf.apache.org/faq.html#FAQ-AreJAXWSclientproxiesthreadsafe%253F" rel="noreferrer">CXF seems to be so if you take precautions</a>. If JAX-WS and <a href="http://metro.java.net/" rel="noreferrer">Metro</a> in particular is not thread safe, is there any way of ensuring thread safety without synchronizing access to port or ws operations?</p>