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

From: David Holmes (
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 -

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