...
Wiki Markup |
---|
<ac:structured-macro ac:name="anchor" ac:schema-version="1" ac:macro-id="0402ee513267c6ec-5ba41755-45464a4e-b41298ca-99a73bb26f8a2f2eca552735"><ac:parameter ac:name="">CON20-EX1</ac:parameter></ac:structured-macro> *TSM02-EX1:* Programs are permitted to start a background thread (or threads) during class initialization, provided the thread cannot access any fields. For example, the {{ObjectPreserver}} class (based on \[[Grand 2002|AA. Bibliography#Grand 02]\]) shown below provides a mechanism for storing object references, which prevents an object from being garbage-collected, even when the object is never again de-referenced. |
...
This is a singleton class (see rule MSC16MSC11-J. Address the shortcomings of the Singleton design pattern for more information on how to defensively code singleton classes). The initialization involves creating a background thread using the current instance of the class. The thread waits indefinitely by invoking Object.wait()
. Consequently, this object persists for the remainder of the JVM's lifetime. Because the object is managed by a daemon thread, the thread cannot interfere with normal shutdown of the JVM.
...
<ac:structured-macro ac:name="unmigrated-wiki-markup" ac:schema-version="1" ac:macro-id="bb443fb9fd032bd9-1393900e-46cc474b-a2088f88-f380056658a7002e65b94ff5"><ac:plain-text-body><![CDATA[ | [[Bloch 2005b | AA. Bibliography#Bloch 05b]] | 8. "Lazy Initialization" | ]]></ac:plain-text-body></ac:structured-macro> |
<ac:structured-macro ac:name="unmigrated-wiki-markup" ac:schema-version="1" ac:macro-id="744976508dcb1f7d-0dd28ecd-4ada4b28-aac696c1-1cca8390533a559ae5628c7d"><ac:plain-text-body><![CDATA[ | [[Grand 2002 | AA. Bibliography#Grand 02]] | Chapter 5, Creational Patterns, Singleton | ]]></ac:plain-text-body></ac:structured-macro> |
...