[concurrency-interest] Spring DispatcherServlet safe publication question

Dhanji R. Prasanna dhanji at gmail.com
Thu Mar 6 02:45:02 EST 2008


Jason:
But the fields are not volatile, is there a guarantee that subsequent
request threads will see the value set by init()?
Dhanji.

On Thu, Mar 6, 2008 at 2:43 PM, Jason T. Greene <jason.greene at redhat.com>
wrote:

> Hi Dhanji,
>
> This is OK, since the servlet spec guarantees that init() is called only
> once, and before any requests are serviced.
>
> Dhanji R. Prasanna wrote:
> > Hello again,
> >
> > This question has been bugging me for a *long* time. Nobody (and no
> > docs) seem to adequately address this problem for me.
> >
> > Spring's
> > DispatcherServlet:
> http://fisheye1.cenqua.com/browse/springframework/spring/src/org/springframework/web/servlet/DispatcherServlet.java?r=1.100
> > ...has several non-volatile, non-final fields for various pluggable
> > services (ThemeResolver, ViewResolver, etc.). These are set by equally
> > various private unsynchronized methods which cascade down from
> > HttpServlet.init(), itself also unsynchronized.
> >
> > The problem I have is that this seems like it could lead to incoherent
> > values between the startup thread's view of DispatcherServlet and any
> > subsequent request threads. Since there is no lock or synchronization, I
> > cannot find a guarantee that request threads will see the value set in
> > the init thread (even though they are chronologically sequenced ok). All
> > these fields are also non-volatile. It looks like a classic unsafe
> > publication problem to me.
> >
> > Worse, there are no default values, so request threads could end up
> > biting NPEs.
> >
> > This seems like a gross flaw in code that's deployed virtually
> > everywhere. Why isn't there more clamor about this? Or am I just totally
> > nuts (I *hope* so)?
> > I know Tim has talked for a long time about (lack of) safe publication
> > guarantees in the Spring injector itself... but I could not find any
> > concrete examples.
> >
> > @Jason: Yes I have JCiP, though it was hell finding it in Australian
> > book stores--thanks for the reck! =)
> >
> > Dhanji.
> >
> >
> > ------------------------------------------------------------------------
> >
> > _______________________________________________
> > Concurrency-interest mailing list
> > Concurrency-interest at altair.cs.oswego.edu
> > http://altair.cs.oswego.edu/mailman/listinfo/concurrency-interest
>
>
> --
> Jason T. Greene
> JBoss, a division of Red Hat
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: /pipermail/attachments/20080306/c84a24aa/attachment.html 


More information about the Concurrency-interest mailing list