By tgautier
via jeremymanson.blogspot.com
Published: Aug 25 2008 / 14:46
One thing I have noticed among Java API users is that some don't seem to know that there is a difference between StringBuffer and StringBuilder. There is: StringBuffer is synchronized, and StringBuilder isn't. (The same is true for Vector and ArrayList, as well as Hashtable and HashMap). StringBuilder avoids extra locking operations, and therefore you should use it where possible.



Comments
tanesha.net replied ago:
Afair this is mentioned even by the SCJP5, so, kind of old news.
(That said, the general point about being careful when doing multi-threaded programming still holds, but rarely news)
paul_houle replied ago:
Well, I like the theme that "synchronizing an object doesn't really make it thread safe", though, it's an issue that Java has dealt with for a long time. I remember the early days of Swing, where it was realized that the fully synchronized approach just wasn't going to work.
Voters For This Link (28)
Voters Against This Link (3)