...
Similarly, it is inappropriate to start threads from constructors. (See guideline TSM01-J. Do not let the "(this" ) reference escape during object construction for more information). Creating timers that perform recurring tasks and starting those timers from within code responsible for initialization introduces liveness issues.
...
| Wiki Markup |
|---|
<ac:structured-macro ac:name="anchor" ac:schema-version="1" ac:macro-id="2d70a7d3522de01f-1603dd0d-4c334ef3-95768b53-0129269367fda7e4d984c959"><ac:parameter ac:name="">CON20-EX1</ac:parameter></ac:structured-macro> *TSM02-EX1:* It is permissible to start a background thread during class initialization provided the thread does not access any fields. For example, the {{ObjectPreserver}} class (based on \[[Patterns 2002|AA. Java References#Patterns 02]\]) shown below provides a mechanism for storing object references, which prevents an object from being garbage-collected, even if the object is not de-referenced in the future. |
...