If I have a class as follows - ( Code taken from SCJP book page 764)
would it be right to say that the above class would not be thread safe if it also had a non private constructor that accepted a StringBuilder? Same if it was even a StringBuffer. Would that be correct?
Joined: Sep 06, 2012
This topic is resolved as I've found out the answer. The answer is yes, since I can send the same StringBuilder reference to different objects and since synchronized methods only block same instance's threads, having a public constructor that accepts the StringBuilder object would make this class unsafe for thread safety.
subject: Synchronized methods alone may not make a class thread safe- right?