RE: JavaMemoryModel: String literals and String.intern()

From: David Holmes (dholmes@dltech.com.au)
Date: Sat Apr 17 2004 - 08:08:43 EDT


Tom Hawtin wrote:
> In the case above, the class' Class will have a reference to the String.
> The Class cannot disappear while the method is executing. Therefore,
> there is no data race. However you can easily create a race using
>
> synchronized ("some ".concat("string").intern()) {
>
> which would be your own fault.

>From an exclusion perspective there is no problem.

But technically from a JMM perspective if different threads actually see a
different interned string instance then there is no happens-before
relationship connecting the unlock and a subsequent lock.

David Holmes

-------------------------------
JavaMemoryModel mailing list - http://www.cs.umd.edu/~pugh/java/memoryModel



This archive was generated by hypermail 2b29 : Thu Oct 13 2005 - 07:01:04 EDT