You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@tomcat.apache.org by Chris Rogers <ja...@comcast.net> on 2002/08/20 19:01:49 UTC

broken locking in StandardWrapper.allocate()

In StandardWrapper.java lines 651 through 664 of
Tomcat 4.0.4, the double-check locking idiom is used
to avoid synchronization.

The double-check locking idiom does not work
reliably in Java.  For reasons why, see:
http://www.cs.umd.edu/~pugh/java/memoryModel/DoubleCheckedLocking.html

The result of using the current code is that requests can
be processed (the servlet's service method can be called)
before the servlet's init method has completed and/or before
values written in init are visible to other threads that are
running the service method.

To fix, take out the outermost "if" statement.  That is,
remove "if (instance == null) { ... }" but keep the code
inside the "if" statement as is.



--
To unsubscribe, e-mail:   <ma...@jakarta.apache.org>
For additional commands, e-mail: <ma...@jakarta.apache.org>