https://issues.apache.org/bugzilla/show_bug.cgi?id=49972

--- Comment #3 from Chuck Caldarale <chuck.caldar...@unisys.com> 2010-09-22 
10:20:36 EDT ---
(In reply to comment #2)
> It looks scarier than that. 
> In short, see
> http://www.cs.umd.edu/~pugh/java/memoryModel/DoubleCheckedLocking.html

Not all double-checked locking is evil.

The simple fix is to just reverse these two lines:

                    currentDateGenerated = now;
                    currentDate = format.format(new Date(now));

By setting currentDate prior to currentDateGenerated, the potential of
returning null is eliminated, and unnecessary locking is still avoided.  (This
is in addition to making the field private, as Sebb noted.)

Case 2 is not a problem; the Java language spec requires operations to be
visible to other threads in program order, so the all operations for building
the new formatted String must be complete before the reference to it is stored
in the field.

 - Chuck

-- 
Configure bugmail: https://issues.apache.org/bugzilla/userprefs.cgi?tab=email
------- You are receiving this mail because: -------
You are the assignee for the bug.

---------------------------------------------------------------------
To unsubscribe, e-mail: dev-unsubscr...@tomcat.apache.org
For additional commands, e-mail: dev-h...@tomcat.apache.org

Reply via email to