Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > Java > Re: baseline performance test using java ...

Reply
Thread Tools

Re: baseline performance test using java ...

 
 
Abu Yahya
Guest
Posts: n/a
 
      07-03-2011
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.
 
Reply With Quote
 
 
 
 
Abu Yahya
Guest
Posts: n/a
 
      07-04-2011
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.
 
Reply With Quote
 
 
 
 
lewbloch
Guest
Posts: n/a
 
      07-04-2011
On Jul 3, 11:33*am, Abu Yahya <abu_ya...@invalid.com> 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.


Well, no. You might want a 'StringBuffer', but it's hardly a need.

--
Lew
 
Reply With Quote
 
lewbloch
Guest
Posts: n/a
 
      07-04-2011
Abu Yahya wrote:
> Patricia Shanahan wrote:
>> Abu Yahya wrote:
>>> 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.


That's a small part of the story, and not accurate anyway.

StringBuffer sb;
...
sb.append( firstString ).append( secondString );

/happens-before/ guarantees that the second 'append()' will
concatenate after the first one. Once the second 'append()'
completes, all threads are guaranteed to see the effects of both
'append()'s. The synchronization inbuilt to 'StringBuffer' does not
guarantee that some thread won't intervene between the two
'append()'s.

--
Lew
 
Reply With Quote
 
Arne Vajhøj
Guest
Posts: n/a
 
      07-23-2011
On 7/3/2011 2:45 PM, 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.


StringBuffer is better than StringBuilder in the case where
if >1 threads append N characters to it, then you are happy
if you get N characters appended don't care about the order.
That is practically never the case. The order of characters
is almost always significant.

Arne

 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Baseline GUI Architecture (was: Baseline GUI Prototype?) Stefan Ram Java 3 11-20-2011 02:18 AM
Cisco Security Baseline Configuration rhett.thompson@gmail.com Cisco 2 03-01-2006 02:37 PM
vertical-align baseline moving table tshad HTML 5 02-10-2005 04:58 PM
Help with MS Baseline Security Analyzer ECLiPSE 2002 Computer Support 2 05-05-2004 11:26 PM
test test test test test test test Computer Support 2 07-02-2003 06:02 PM



Advertisments
 



1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57