Versions Compared

Key

  • This line was added.
  • This line was removed.
  • Formatting was changed.

...

Wiki Markup
This allows the new thread to access the {{this}} reference of the current object \[[Goetz 02|AA. Java References#Goetz 02]\], \[[Goetz 06|AA. Java References#Goetz 06]\]. Notably, the constructor {{Thread()}} is [alien|BB. Definitions#alien method] to the class {{ThreadStarter}}. 

Compliant Solution (thread)

...

Wiki Markup
It is safe to create the thread in the constructor as long as it is not started until object construction is over. This is because "A call to start() on a thread happens-before any actions in the started thread." \[[JLS 05|AA. Java References#JLS 05]\]. However, this approach may incur more maintainability costs.

Risk Assessment

Allowing the this reference to escape may result in improper initialization and runtime exceptions.

...