BIRT 3.7
Written by: Michael Williams
Featured Refcardz: Top Refcardz:
  1. Scrum
  2. Apache Maven 2
  3. Essential MySQL
  4. Node.js
  5. Groovy
  1. jQuery Selectors
  2. Ajax
  3. Java
  4. Spring Config.
  5. Java Concurrency

Link Details

Link 106894 thumbnail
User 207620 avatar

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.
  • 28
  • 3
  • 3175
  • 3

Comments

Add your comment
User 293051 avatar

tanesha.net replied ago:

0 votes Vote down Vote up Reply

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)

User 281687 avatar

paul_houle replied ago:

0 votes Vote down Vote up Reply

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.

Add your comment


Html tags not supported. Reply is editable for 5 minutes. Use [code lang="java|ruby|sql|css|xml"][/code] to post code snippets.