Constructors shouldn't start threads

Constructors shouldn't start threads. According to Java Concurrency in Practice, by Brian Goetz and others (an excellent book), there are two problems with starting a thread in a constructor (or static initializer):

There's nothing wrong with creating a thread object in a constructor or static initializer - just don't start it there.

The alternative to starting a thread in the constructor is to simply start the thread in an ordinary method instead.


See Also :
Constructors in general
Don't let this reference escape
Would you use this technique?
Yes   No   Undecided   
© 2013 Hirondelle Systems | Source Code | Contact | License | RSS
Individual code snippets can be used under this BSD license - Last updated on August 30, 2012.
Over 2,400,000 unique IPs last year - Built with WEB4J.
- In Memoriam : Bill Dirani -