...
For these purposes, instead of a constructor, a class or an instance method is sometimes frequently used for initialization, depending on whether the member object is static
or not. The method checks whether the instance has already been created and if not, creates it. If the instance already exists, it simply returns it. This is shown below:
...
Wiki Markup |
---|
*EX2:* "Although the \[noncompliant form of the\] double-checked locking idiom cannot be used for references to objects, it can work for 32-bit primitive values (e.g., int's or float's). Note that it does not work for long's or double's, since unsynchronized reads/writes of 64-bit primitives are not guaranteed to be atomic." \[[Pugh 04|AA. Java References#Pugh 04]\]. See [CON25-J. Ensure atomicity when reading and writing 64-bit values] for more information. |
...