On Wed January 13 2010 6:39:04 pm Henk Flipman wrote: > Hi, > > I'm new to Apache CXF and am trying to find a definitive answer for how to > use Apache CXF clients with Spring in a multi-threaded environment. > > I've seen several types of examples and implementations but it's not clear > to me what is supposed to work and what is not supposed to work in a > multi-threaded environment. > > I've seen implementations where there is 1 JaxWsProxyFactoryBean and each > thread that needs a client calls 'factory.create()'. That assumes that the > factory is thread-safe when it comes to creating clients. Is this approach > correct?
With 2.2.5 and later, yes. With 2.2.4 and earlier, create always returned the same client, so no. > Other implementations I've seen use 1 client across all threads. And I'm > pretty sure that is not thread safe. Correct? Well, no. CXF clients are thread safe EXCEPT for the request context (but that can also be made into a thread local) and stuff specific to the conduit. See the faq: http://cxf.apache.org/faq.html > And I've seen implementations where each thread creates its own > JaxWsProxyFactoryBean and then uses it to create its own client. That of > course is 'thread safe' since nothing is shared between threads but won't > perform well probably. Right. The more popular approach is to actually create a "Pool" of clients. When a thread needs one, it grabs one from a pool and puts it back when done. If there aren't any left in the pool, a new one is created. That way, if only a single thread at a time really needs one, only one is created. Keeps the resource requirements down to a minimum of what's really needed while also making it faster to "grab" a client if one is already available. Dan > Can somebody provide a definitive answer? I'm using CXF 2.1.8. > > Thanks. > > Henk > -- Daniel Kulp [email protected] http://www.dankulp.com/blog
