drac yang wrote:from the above thread, does it mean that because the granularity of the synchronization of StringBuffer is only method, so it would not be safe when it comes to uses of inter-methods.
Correct. And the same is true of any "synchronized class" (which isn't actually a thing, but which is what people sometimes call a class whose public methods are all synchronized). Using only synchronization, there's no way for a class to ensure exclusivity or atomicity across multiple method calls.
It is possible to do something like that using the facilities in java.util.concurrent, but I wouldn't advise it in general, and I'm not aware of any classes that do it.