tomcat-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
Subject DO NOT REPLY [Bug 49986] Double-check locking. Possible data-race in JspServletWrapper
Date Thu, 30 Sep 2010 05:27:29 GMT

Tim Whittington <> changed:

           What    |Removed                     |Added
          Component|Jasper                      |Jasper
            Version|6.0.29                      |trunk
            Product|Tomcat 6                    |Tomcat 7
   Target Milestone|default                     |---

--- Comment #3 from Tim Whittington <> 2010-09-30 01:27:22 EDT ---
This is actually one of the rare cases that DCL is a decent solution, but the
current implementation is broken.

The fix for getServlet (now Java 5 has come along) is a volatile reload flag.
This forces an in order write of the new servlet object and the 'theServlet'
reference (as long as the write to reload is the last step in the update), as
well as forcing a read barrier (and thus a consistent read of 'theServlet' and
the new servlet object) for any thread entering getServlet after a reload is

setServletClassLastModifiedTime can be fixed by making
servletClassLastModifiedTime volatile (again since Java 5).
(This could be done with an AtomicLong and a busy loop compareAndSet, but the
volatile DCL is a more minor change and the performance diff is probably
        final AtomicLong lastModifiedTime = new AtomicLong();

        while (true) {
            long current = lastModifiedTime.get();
            if (current < lastModified) {
                if (lastModifiedTime.compareAndSet(current, lastModified)) {
                    reload = true;
            } else {

I'll move this to Tomcat 7 and look at a fix there - depending on the
confidence we have it may find it's way back to 6.x (although I've been running
Tomcat in production for a decade and have never seen a practical failure from

Configure bugmail:
------- You are receiving this mail because: -------
You are the assignee for the bug.

To unsubscribe, e-mail:
For additional commands, e-mail:

View raw message