“A common mistake that can let the this reference escape during construction is to start a thread from a constructor. When an object creates a thread from its constructor, it almost always shares its this reference with the new thread, either explicitly (by passing it to the constructor) or implicitly (because the Thread or Runnable is an inner class of the owning object). The new thread might then be able to see the owning object before it is fully constructed. There's nothing wrong with creating a thread in a constructor, but it is best not to start the thread immediately. Instead, expose a start or initialize method that starts the owned thread. (See Chapter 7 for more on service lifecycle issues.) Calling an overrideable instance method (one that is neither private nor final) from the constructor can also allow the this reference to escape. If”
―
Java Concurrency in Practice
Share this quote:
Friends Who Liked This Quote
To see what your friends thought of this quote, please sign up!
0 likes
All Members Who Liked This Quote
None yet!
This Quote Is From
Browse By Tag
- love (100950)
- life (78985)
- inspirational (75543)
- humor (44230)
- philosophy (30807)
- inspirational-quotes (28700)
- god (26816)
- truth (24630)
- wisdom (24454)
- romance (24272)
- poetry (23107)
- life-lessons (22507)
- quotes (20908)
- death (20490)
- happiness (18909)
- hope (18453)
- faith (18291)
- inspiration (17225)
- travel (16908)
- spirituality (15628)
- relationships (15432)
- religion (15353)
- motivational (15241)
- life-quotes (15208)
- love-quotes (15044)
- writing (14907)
- success (14151)
- motivation (13096)
- time (12808)
- science (12043)