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 pass 'this' out of a constructor
Would you use this technique?
Yes   No   Undecided   
© 2018 Hirondelle Systems | Source Code | Contact | License | RSS
Individual code snippets can be used under this BSD license - Last updated on September 21, 2013.
Over 2,000,000 unique IPs last year - Built with WEB4J.
- In Memoriam : Bill Dirani -