[concurrency-interest] Spring DispatcherServlet safe publication question
crazybob at crazybob.org
Mon Mar 10 00:20:39 EDT 2008
As a practical matter, it would seem either:
a) The init thread calls init() and then passes the servlet instance off to
request threads in a thread safe way.
b) All threads have access to the servlet and the init thread notifies the
request threads that they can call service().
Either way, I think it's safe, right?
On Wed, Mar 5, 2008 at 6:30 PM, Dhanji R. Prasanna <dhanji at gmail.com> 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:
> ...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! =)
> Concurrency-interest mailing list
> Concurrency-interest at altair.cs.oswego.edu
-------------- next part --------------
An HTML attachment was scrubbed...
More information about the Concurrency-interest