Win a copy of Murach's Python Programming this week in the Jython/Python forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic

difference between synchronization on StringBuffer and StringBuilder object ?  RSS feed

 
gurpeet singh
Ranch Hand
Posts: 924
1
Fedora Java Netbeans IDE
  • 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
Sheriff
Posts: 22840
119
C++ Chrome Eclipse IDE Firefox Browser Java jQuery Linux VI Editor Windows
  • 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
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!