[concurrency-interest] Spring DispatcherServlet safe publication question

Dhanji R. Prasanna dhanji at gmail.com
Wed Mar 5 21:30:59 EST 2008

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:
...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

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*
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! =)

-------------- next part --------------
An HTML attachment was scrubbed...
URL: /pipermail/attachments/20080306/2da5f8d2/attachment.html 

More information about the Concurrency-interest mailing list