Re: JavaMemoryModel: Mutually exclusive goals for Java memory model

From: Bill Pugh (pugh@cs.umd.edu)
Date: Mon Apr 22 2002 - 12:29:02 EDT


At 5:22 PM -0700 4/18/02, Thomas Wang wrote:
>
>
>Also, refresh my memory about how should we write immutable object source
>codes now? (under the new memory model)

OK, here is a guideline for creating immutable objects under the new
memory model:

If you want an object X to be immutable in the presence of data races
by uses of the object:

  * every field of X should be final
  * any data structure reachable from fields of X should be either:
        - immutable, or
        - only reachable by threads other than the creating
          thread via fields of object X

For example, String will contain a final reference to a character
array, and the only way for another thread to see that character
array is through the final reference.

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



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