This week's book giveaway is in the Clojure forum.
We're giving away four copies of Clojure in Action and have Amit Rathore and Francis Avila on-line!
See this thread for details.
Win a copy of Clojure in Action this week in the Clojure forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

difference between synchronization on StringBuffer and StringBuilder object ?

 
gurpeet singh
Ranch Hand
Posts: 924
1
Fedora Java Netbeans IDE
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
please consider the following code :





here i'm locking on StringBuffer object which has synchronized methods. i would like to know what if i use StringBuilder object. I tried running the code using Stringbuilder and got the same output. i would like to know is there any difference between the two scenarios in terms of thread-safety, synchronization etc. ?
 
Henry Wong
author
Marshal
Pie
Posts: 20836
75
C++ Chrome Eclipse IDE Firefox Browser Java jQuery Linux VI Editor Windows
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
gurpeet singh wrote:please consider the following code :





here i'm locking on StringBuffer object which has synchronized methods. i would like to know what if i use StringBuilder object. I tried running the code using Stringbuilder and got the same output. i would like to know is there any difference between the two scenarios in terms of thread-safety, synchronization etc. ?


The StringBuffer class methods are synchronized. The StringBuilder class methods are not synchronized. Based on the way your application uses the string buffer/builder, this shouldn't make any difference.

Henry
 
I agree. Here's the link: http://aspose.com/file-tools
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic