Re: JavaMemoryModel: init methods

From: Bill Pugh (
Date: Mon Sep 25 2000 - 18:14:20 EDT

>A couple questions about construction/initialization safety:
>If I understand correctly, some of the proposed fixes to JMM are
>designed so that immutable objects can be accessed without
>synchronization once they are constructed.

Perhaps. The really important thing is to make String absolutely
immutable, without which security is impossible.

Removing the need for immutable objects in general is a secondary
concern (but still important). As you note, the problem with
recommending this in general as a way to write programs is that it
depends on using very particular paradigms in order to get true
immutability (e.g., use final fields, ...).

For example, there is no way to define an immutable externalizable
object (since you can't set the final fields in readExternal).

Bean-style construction I don't worry about so much, because if an
object has explicit setFoo methods, it clearly isn't immutable.

As far as stuff like Applets and Servlets, yes the documentation
needs to be clearer about the synchronization performed by
containers. I think the right answer is to say that containers do any
required synchronization, unless it is possible for a method to be
invoked simultaneously (e.g., a service call to a servlet), in which
case the servlet must perform the required synchronization.


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