Jump to content

  • Log In with Google      Sign In   
  • Create Account


[java] stringbuffer optimization


Old topic!
Guest, the last post of this topic is over 60 days old and at this point you may not reply in this topic. If you wish to continue this conversation start a new topic.

  • You cannot reply to this topic
1 reply to this topic

#1 sma202   Members   -  Reputation: 122

Like
Likes
Like

Posted 23 January 2001 - 08:05 AM

Heres something I was wondering about, suppose we have the following statement: StringBuffer sb = new StringBuffer() sb.append(a); sb.append(b); sb.append©; And contrast it with this code: StringBuffer sb = new StringBuffer() synchronized (sb) { sb.append(a); sb.append(b); sb.append©; } Is the second piece of code faster because the first code has to perform 3 internal locks within the stringbuffer class versus only one in second piece of code?

Sponsor:

#2 GKW   Members   -  Reputation: 200

Like
Likes
Like

Posted 23 January 2001 - 04:42 PM

I would be interested in the answer to this. But unless you need the string concat "+" operation I would suggest making your own string class that does not check for sync, assuming you don''t need it. I assume that even if it has a lock from the start, the stringbuffer will still check for a lock.

The fanatic is incorruptible: if he kills for an idea, he can just as well get himself killed for one; in either case, tyrant or martyr, he is a monster.
--EM Cioran

Opere Citato




Old topic!
Guest, the last post of this topic is over 60 days old and at this point you may not reply in this topic. If you wish to continue this conversation start a new topic.



PARTNERS