Thank you Daniel, 

I was afraid there would be issues.  Unfortunately the FAQ doesn't explain how 
to do make the client calls threadsafe when using Spring.  

I took a stab at combining your reply with the FAQ instructions and how I 
currently make CXF service calls with Spring.  Could you (or anybody) please 
look at it and correct me if I got it wrong?

1) In the client, get a reference to the proxy:

ApplicationContext context = new ClassPathXmlApplicationContext(
          new String[] {"mySpringContext-client.xml"});
MyClientIF client = (MyClientIF)context.getBean("myServiceClientBeanID");

2) Set the service client bean's requestContext to thread.local (presumably the 
bean implements the BindingProvider interface automatically):

((BindingProvider)client).getRequestContext().put("thread.local.request.context",
 "true");

3) Pass 'client' to the threads.

4) The threads call the service methods (presumably CXF calls .requestContext() 
automatically as part of the service call):

client.MyMethod();


Thanks,

bruno 

-----Original Message-----
From: Daniel Kulp [mailto:dk...@apache.org] 
Sent: Wednesday, January 20, 2010 2:58 PM
To: users@cxf.apache.org
Cc: Bruno Melloni
Subject: Re: Spring/CXF <jaxws:client> is it thread-safe?


See the faq:
http://cxf.apache.org/faq.html

Basically, if you use the request context, you could have issues if you don't 
set the request context to be thread local.   

Dan


On Wed January 20 2010 12:49:22 pm Bruno Melloni wrote:
> The approach of relying on Spring to get the CXF client object from the
>  context is so convenient that I rarely think much about it.
> 
> But I find myself needing to call the client from several concurrent
>  threads and I am not sure but I believe that when I call context.getBean()
>  I am retrieving a singleton instance of the client object.  Is that going
>  to be an issue when I call the same service method from multiple threads?
> 
> The code behind the service call is already thread-safe.  If I were calling
>  it locally from multiple threads it would not be a problem.
> 

-- 
Daniel Kulp
dk...@apache.org
http://www.dankulp.com/blog

Reply via email to