In Java Docs it says, StringBuffer
's methods are synchronized
. Then why do I still need to manually synchronize
the StringBuffer
in the example given in this question: here
I read somewhere that it is not worthy of using StringBuffer
over StringBuilder
because it (StringBuffer) is slower than StringBuilder
. In this way, these two are same like Vector
and ArrayList
.
But I was wondering, why do we call it (StringBuffer
or Vector
) a Thread Safe
classes, when we still need to manually enclose them in synchronized
block like in the example mentioned in above link. Why can't I rely on them. Can anyone explain & clear my doubts.
Is there any way to check StringBuffer is really a Thread Safe class.