...
Wiki Markup |
---|
However, this solution requires the assignment of a new {{Helper}} instance to {{helper}} from Foo's constructor. According to the _Java Language Specification_, [§17.5.2, "Reading Final Fields During Construction"|http://java.sun.com/docs/books/jls/third_edition/html/memory.html#17.5.2] \[[JLS 2005|AA. Bibliography#JLSReferences#JLS 05]\] |
A read of a final field of an object within the thread that constructs that object is ordered with respect to the initialization of that field within the constructor by the usual happens-before rules. If the read occurs after the field is set in the constructor, it sees the value the final field is assigned; otherwise, it sees the default value.
...
Wiki Markup |
---|
According to JSR-133, Section 9.2.3, "Static Final Fields" \[[JSR-133 2004|AA. Bibliography#JSRReferences#JSR-133 04]\] |
The rules for class initialization ensure that any thread that reads a
static
field will be synchronized with the static initialization of that class, which is the only place where static final fields can be set. Thus, no special rules in the JMM are needed for static final fields.
...
Wiki Markup |
---|
The JMM guarantees that any final fields of an object are fully initialized before a published object becomes visible \[[Goetz 2006|AA. Bibliography#GoetzReferences#Goetz 06]\]. By declaring {{n}} final, the {{Helper}} class is made [immutable|BB. Glossary#immutable]. Furthermore, if the {{helper}} field is declared volatile in compliance with rule [VNA01-J. Ensure visibility of shared references to immutable objects], {{Helper}}'s reference is guaranteed to be made visible to any thread that calls {{getHelper()}} only after {{Helper}} has been fully initialized. |
...
<ac:structured-macro ac:name="unmigrated-wiki-markup" ac:schema-version="1" ac:macro-id="039436490ff0147a-f3a4fef7-492b4219-b13ea7e6-63ea79a6f7bf94382adaf7f6"><ac:plain-text-body><![CDATA[ | [[API 2006 | AA. Bibliography#API References#API 06]] |
| ]]></ac:plain-text-body></ac:structured-macro> |
<ac:structured-macro ac:name="unmigrated-wiki-markup" ac:schema-version="1" ac:macro-id="cd7f9054b89eef94-0f235ac6-440d4552-a893a8ff-b702be82b8052a725f147124"><ac:plain-text-body><![CDATA[ | [[Bloch 2001 | AA. Bibliography#Bloch References#Bloch 01]] | Item 48. Synchronize access to shared mutable data | ]]></ac:plain-text-body></ac:structured-macro> |
<ac:structured-macro ac:name="unmigrated-wiki-markup" ac:schema-version="1" ac:macro-id="af9ada43142021b7-132c9942-4bdf4607-93d59151-257aada2e86eacbe8fc6ded4"><ac:plain-text-body><![CDATA[ | [[Goetz 2006 | AA. Bibliography#Goetz References#Goetz 06]] | Section 3.5.3, Safe Publication Idioms | ]]></ac:plain-text-body></ac:structured-macro> |
<ac:structured-macro ac:name="unmigrated-wiki-markup" ac:schema-version="1" ac:macro-id="15f3c89c01255d0d-8685b61d-49954ea6-9f21ab92-59d1d40a8340add2782d4174"><ac:plain-text-body><![CDATA[ | [[Goetz 2007 | AA. Bibliography#Goetz References#Goetz 07]] | Pattern #2, One-Time Safe Publication | ]]></ac:plain-text-body></ac:structured-macro> |
<ac:structured-macro ac:name="unmigrated-wiki-markup" ac:schema-version="1" ac:macro-id="2540af077078d399-c82661eb-488a4851-bef09ef7-8a2424c4c2820bd7626f55b0"><ac:plain-text-body><![CDATA[ | [[JPL 2006 | AA. Bibliography#JPL References#JPL 06]] | 14.10.2, Final Fields and Security | ]]></ac:plain-text-body></ac:structured-macro> |
<ac:structured-macro ac:name="unmigrated-wiki-markup" ac:schema-version="1" ac:macro-id="e11df997101e97b6-598b2656-4716413a-afa09393-fb21c67ba4eccf35782bcc0a"><ac:plain-text-body><![CDATA[ | [[Pugh 2004 | AA. Bibliography#Pugh References#Pugh 04]] |
| ]]></ac:plain-text-body></ac:structured-macro> |
...