On Jan 10, 2013, at 12:06 PM, kongar <[email protected]> wrote:
> I seem to be having multi-threading problems with a shared CXF client port,
> and I'm hoping that someone here can point me to the right direction as to
> how to debug this. My setup is this:
>
> 1. I create a port instance and cache it. I have the following
> configuration for the port to make it thread safe (according to Apache FAQ
> and some forum posts):
>
> ((BindingProvider)
> port).getRequestContext().put("thread.local.request.context", Boolean.TRUE);
> ((BindingProvider)
> port).getRequestContext().put(HTTPClientPolicy.class.getName(), new
> HTTPClientPolicy());
>
> 2. I spawn off multiple threads with each one using the same port instance.
> 3. For each thread, the port is configured with the following:
> a.) properties are added to the request context (such as client
> properties, url, timeout)
OK. That should be OK.
> b.) TLSClientParameters are set in the port's HTTPConduit (with the
> client parameters having the same values for all threads so having them
> shared should be OK)
Well, if all the threads are modifying them at the same time, that could cause
concurrent modification issues. I'd suggest just setting this up front once
and leaving it.
> c.) Interceptors (WSS4JOutInterceptor) are added to the ClientProxy
That won't work. The interceptor chains are not stored per thread. Thus, if
you have 4 threads adding stuff to the chain, the invokes on the 4 threads
would get all of those interceptors.
> 4. Have each thread concurrently invoke the port
>
> So after #4, it seems like all the threads function properly, but there's
> always one where the port never receives a response and eventually times
> out. I've verified that the messages are actually being sent properly and
> that the responding server receives them all just fine. But that one thread
> with that one port never seems to receive it. As the FAQ states that the
> response context is always thread local, I'm not sure where to look for in
> my code that is causing this problem. And I do believe this is a thread
> safety issue as when I changed Step #1 to not cache the port, I don't get
> this problem anymore. Any help will be appreciated…
No idea how 3c above may affect that. Not really sure. It's definitely
possible that adding an interceptor to the chain while another thread is trying
to use the chain may result in a situation where a chain isn't complete enough
and the response isn't handleable. Not really sure.
Dan
>
> Thanks!
>
>
>
> --
> View this message in context:
> http://cxf.547215.n5.nabble.com/CXF-port-thread-safety-question-tp5721412.html
> Sent from the cxf-user mailing list archive at Nabble.com.
--
Daniel Kulp
[email protected] - http://dankulp.com/blog
Talend Community Coder - http://coders.talend.com