tomcat-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From bugzi...@apache.org
Subject DO NOT REPLY [Bug 49972] Double-check idiom. Possible data-race.
Date Wed, 22 Sep 2010 10:53:28 GMT
https://issues.apache.org/bugzilla/show_bug.cgi?id=49972

--- Comment #1 from Sebb <sebb@apache.org> 2010-09-22 06:53:24 EDT ---
The currentDateGenerated field is read outside the synch. block, and is not
volatile.

So if one thread calls getCurrentDate() and updates the field, another thread
calling getCurrentDate() may see a stale value. 

Now a stale value will be smaller than the proper value, so the worst that can
happen is that the synch. block is invoked unnecessarily. The synch. block will
pick up the true value, and skip the format call if necessary.

However, this assumes that the field is only updated by the getCurrentDate()
method. As the field is not private, that is not guranteed.

Seems to me that the field should be made private, and a comment added to
explain why the double-check is OK in this case.

If read-only access is needed, a getter could be added for the binary field.

-- 
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-unsubscribe@tomcat.apache.org
For additional commands, e-mail: dev-help@tomcat.apache.org


Mime
View raw message