[concurrency-interest] Spring DispatcherServlet safe publication question

Dhanji R. Prasanna dhanji at gmail.com
Mon Mar 10 00:58:47 EDT 2008

On Mon, Mar 10, 2008 at 3:20 PM, Bob Lee <crazybob at crazybob.org> wrote:

> 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.
> or
> b) All threads have access to the servlet and the init thread notifies the
> request threads that they can call service().

So, the servlet is instantiated in StandardWrapper.allocate() using
double-checked locking (as Jason noted) on a non-volatile variable,
"instance". Method getServlet() is a dumb getter that returns a reference to

Im not sure if allocate() is guaranteed to be called only once, i.e. by one
thread (I mean, what's the point of DCLing if it is)? And the servlet spec
only requires that the init() method be called once. Which happens as

Therefore reading threads (or any subsequent thread calling allocate() ) can
see a partially constructed servlet instance--correct?

-------------- next part --------------
An HTML attachment was scrubbed...
URL: /pipermail/attachments/20080310/36873e84/attachment-0001.html 

More information about the Concurrency-interest mailing list