My understanding is they do not support Spring Prototype beans....so your
resource classes are Singletons.  Therefore any members are most likely not
Threadsafe unless they are using ThreadLocal or some such trickery under the
covers.


On Tue, Aug 25, 2009 at 8:38 AM, Nicola D'Elia <[email protected]>wrote:

> Hi,
> i have a similar question.
>
> I have a spring bean exposed as web service: it is a singleton and gets the
> context injected to work with the http session:
>
> ...
>    @Resource
>    private WebServiceContext context;
>
>    public String login(String username) {
>        String challenge = auth.login(username);
>        if (challenge != null) {
>             ((HttpServletRequest)
>
> context.getMessageContext().get(HTTP_REQUEST)).getSession().setAttribute(USERNAME,
> username);
> ...
>
>
> Is it safe or i should turn the bean into a prototype ?
>
>
>
> Thanks,
> Nicola
>
>
>
>
> On Fri, Aug 21, 2009 at 3:00 PM, Sergey Beryozkin <[email protected]
> >wrote:
>
> > Hi
> >
> > I thought you were asking about fileds like
> >
> > @Context
> > private HttpHeaders headers;
> >
> > such fields are indeed thred-safe even with singleton resource classes,
> it
> > is thread-safe proxies which are injected in such cases.
> >
> > Now, as far as supporting Spring prototypes is concerned I haven't got to
> > fixing this JIRA yet :
> >
> > http://issues.apache.org/jira/browse/CXF-2197
> >
> > You might want to try using CXFNonSpringJaxrsServlet and set a
> jaxrs.scope
> > parameter to 'prototype' or register a JAXRS Application impl - that is
> the
> > only way at the moment to work with prototypes (programmatic config is
> > supported too)
> >
> > cheers, Sergey
> >
> > ----- Original Message ----- From: "Nathaniel Auvil" <
> > [email protected]>
> > To: <[email protected]>
> > Sent: Friday, August 21, 2009 1:15 PM
> > Subject: Re: Thread Safety
> >
> >
> >
> >  I thought a singleton was not threadsafe by default, such as a Java
> >> Servlet?  I did a more thorough reading of the CXF docs and saw the
> Spring
> >> configured Resource classes are Singletons and not Prototype Beans.  So
> in
> >> other words, each request will share the same instance of my
> >> AccountService
> >> Resource class.  If i have a member variable: private Account account,
> >> this
> >> will be shared by all requests and get overwritten by each request.
> >>  Right?
> >>
> >>
> >>
> >>
> >> On Fri, Aug 21, 2009 at 6:19 AM, Sergey Beryozkin <
> [email protected]
> >> >wrote:
> >>
> >>  Hi
> >>>
> >>> ----- Original Message ----- From: "Nathaniel Auvil" <
> >>> [email protected]>
> >>> To: <[email protected]>
> >>> Sent: Thursday, August 20, 2009 6:18 PM
> >>> Subject: Thread Safety
> >>>
> >>>
> >>>
> >>>  I am implementing JAX-RS web service with CXF and i want to confirm my
> >>>
> >>>> Resource classes are thread safe.  i am thinking they are as the
> >>>> examples
> >>>> show member variables holding various contexts and the like and no
> where
> >>>> down the chain does the "AbstractService" extend java servlet.  Can
> >>>> someone
> >>>> in the know please confirm?
> >>>>
> >>>>
> >>>>  All the fields containing injected contexts are thread safe, when
> >>> resource
> >>> classes are singletons, so yes resource classes are thread safe.
> >>>
> >>>  and no where down the chain does the "AbstractService" extend java
> >>>
> >>>> servlet.
> >>>>
> >>>>
> >>> Can you clarify please what you meant to say ?
> >>>
> >>> thanks, Sergey
> >>>
> >>>
> >>
> >
>

Reply via email to