[concurrency-interest] Parametric Initialization On Demand Holder Idiom ?
hanson.char at gmail.com
Fri Aug 31 00:41:02 EDT 2007
On 8/30/07, Joe Bowbeer <joe.bowbeer at gmail.com> wrote:
> The value is not safely published here:
> SomethingMore.valueHolder = value;
> That creates a window where another thread could overwrite valueHolder
> before the current thread initializes the singleton.
True. As explained in the outset, this is considered acceptable as
long as the overwriting value comes from one of the contending threads
rather than "out-of-thin-air".
> This is OK for super-safe values like String. Immutable objects with
> all fields final do not require safe publication. In general,
> thread-safe values do require safe publication.
Agree. However, is it possible to contrive an example where a
thread-safe (but not super-safe like immutable) value passed to the
SomethingMore.getInstance(params) would cause a
surprising/unexpected/corrupted/partially-initialized result ?
More information about the Concurrency-interest