[java] stringbuffer optimization
Heres something I was wondering about, suppose we have the following statement:
StringBuffer sb = new StringBuffer()
sb.append(a);
sb.append(b);
sb.append(c);
And contrast it with this code:
StringBuffer sb = new StringBuffer()
synchronized (sb) {
sb.append(a);
sb.append(b);
sb.append(c);
}
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?
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
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
This topic is closed to new replies.
Advertisement
Popular Topics
Advertisement