Posted By:
Richard_Robinson
Posted On:
Friday, April 13, 2001 12:07 PM
I'm unclear about constructors in general, and how they relate to multithreading in particular. Common advice is to make member variables (instance and static) private and synchronize public methods in a class. As well, and in particular, to synchronize getter/setter methods. Java prohibits the using of "synchronized" on a constructor. So I'm guessing that when an object is first created, ie. constructed, that there is ONE and ONLY ONE thread that does the construction? If this is right, then what happens after the first object is created and another object in the same calling object tries to construct the object again. If the to-be-constructed object has several instance variables and the constructor sets th
More>>
I'm unclear about constructors in general, and how they relate to multithreading in particular. Common advice is to make member variables (instance and static) private and synchronize public methods in a class. As well, and in particular, to synchronize getter/setter methods.
Java prohibits the using of "synchronized" on a constructor. So I'm guessing that when an object is first created, ie. constructed, that there is ONE and ONLY ONE thread that does the construction?
If this is right, then what happens after the first object is created and another object in the same calling object tries to construct the object again. If the to-be-constructed object has several instance variables and the constructor sets them... Even if the setter methods are synchronized, isn't there a concurrency issue at work between when the constructor sets the one value and the subsequent call to set the next one?
<<Less