cxf-users mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Ron Grimes <>
Subject RE: jaxws endpoint threadsafe as a Spring singleton?
Date Tue, 02 Mar 2010 16:50:29 GMT
I've used the WebServiceContext for purposes such as to retrieve the client's IP address. Never
had a problem with it. Also, if you look at the source code for WebServiceContextImpl, you'll
see that it uses a ThreadLocal type for the context. And, if you look at the source on ThreadLocal,
you'll see that the documentation reads:

 * This class provides thread-local variables.  These variables differ from
 * their normal counterparts in that each thread that accesses one (via its
 * <tt>get</tt> or <tt>set</tt> method) has its own, independently
 * copy of the variable."

Ron Grimes

-----Original Message-----
From: Kessel, Christopher [] 
Sent: Tuesday, March 02, 2010 8:48 AM
Subject: jaxws endpoint threadsafe as a Spring singleton?

I've defined my bean in Spring as per some examples in the CXF tutorial

<bean id="fooImpl" class="FooServerImpl"></bean>
<jaxws:endpoint id="foo" implementor="#fooImpl"

My FooServerImpl has a reference to the WebServiceContext (because I
have to get to the SerlvetContext for historical reasons).

    private WebServiceContext _wsContext;

The javadoc on WebServiceContext says that _wsContext is relative to the
request being served:

 *  A <code>WebServiceContext</code> makes it possible for
 *  a web service endpoint implementation class to access
 *  message context and security information relative to
 *  a request being served.

So, my question is, if FooServerImpl is a Spring singleton (which I
think is the default, at least in the application I'm working on), would
that mean the _wsContext isn't thread safe since it's related to each
request? If I had 2 requests come in simultaneously, the _wsContext for
the 2nd one would clobber the value set for the first request. Yes?


View raw message