On 7/4/2011 12:15 AM, Patricia Shanahan wrote:
> On 7/3/2011 11:33 AM, Abu Yahya wrote:
>> On 7/3/2011 11:23 PM, lbrt chx _ gemale kom wrote:
>>
>>>>> ~ We have all learned we should avoid String(s) and use
>>>>> StringBuffer(s) or better yet StringBuilder(s) but there is
>>> ~
>>>> Er, no. Strings are great ...
>>> ~
>>> I (obviously) meant to say String(s) if you need to build them
>>> andStringBuilder(s)
>> > if you are working (most of us by now) on some multiprocessing core
>>> ~
>>
>> If you need to build them, you'd need a StringBuilder. And if you need
>> support for multiple threads AND need to modify them, you'd need a
>> StringBuffer.
>
> Often, the StringBuffer locking is not strong enough to be really
> useful. If, for example, a thread needs to append two strings to the
> buffer and have them appear consecutively in the resulting string, it
> needs synchronization at a higher level.
True. StringBuffer's locking will only help in guaranteeing an output in
which either the first string /or/ the second string is /completely/
appended first. If the order matters, the built-in locking won't help.
|