commons-issues mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From "Adrian Shum (JIRA)" <j...@apache.org>
Subject [jira] [Comment Edited] (LANG-833) ToStringBuilder should use StringBuilder
Date Tue, 16 Oct 2012 02:59:04 GMT

    [ https://issues.apache.org/jira/browse/LANG-833?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=13476684#comment-13476684
] 

Adrian Shum edited comment on LANG-833 at 10/16/12 2:59 AM:
------------------------------------------------------------

Support for using StringBuilder in ToStringBuilder.  I believe lang3 allow breaking certain
level of backward compatibility (and afaik it did).  And, most important is, the suggested
usage of ToStringBuilder is mostly for a short-lived string building that is rarely shared
between threads.  

A compromise can be achieved (though I don't think it is really needed :P) is by allowing
an (optional) extra ctor argument in ToStringBuilder to denote whether we want it to be thread-safe
or not (we can keep the default as thread-safe).  Internally, instead of using StringBuffer/StringBuilder
directly, declare buffer as AbstractStringBuilder instead (which is the parent of StringBuffer
and StringBuilder).  Instantiate StringBuffer or StringBuilder according to the ctor argument.

For people who want better performance, they can just explicitly change the usage of ToStringBuilder
from new ToStringBuilder(....) to new ToSTringBuilder(..., THREAD_UNSAFE).  

Sounds feasible to me.  :P
                
      was (Author: adrianshum):
    Support for using StringBuilder in ToStringBuilder.  I believe lang3 allow breaking certain
level of backward compatibility (and afaik it did).  And, most important is, the suggested
usage of ToStringBuilder is mostly for a short-lived string building that is rarely shared
between threads.  

A compromise can be allowing an (optional) extra ctor argument in ToStringBuilder to denote
whether we want it to be thread-safe or not (we can keep the default as thread-safe).  Internally,
instead of using StringBuffer/StringBuilder directly, declare buffer as AbstractStringBuilder
instead (which is the parent of StringBuffer and StringBuilder).  Instantiate StringBuffer
or StringBuilder according to the ctor argument.

For people who want better performance, they can just explicitly change the usage of ToStringBuilder
from new ToStringBuilder(....) to new ToSTringBuilder(..., THREAD_UNSAFE).  

Sounds feasible to me.  :P
                  
> ToStringBuilder should use StringBuilder
> ----------------------------------------
>
>                 Key: LANG-833
>                 URL: https://issues.apache.org/jira/browse/LANG-833
>             Project: Commons Lang
>          Issue Type: Improvement
>          Components: lang.*
>    Affects Versions: 3.1
>            Reporter: Shevek
>
> Rewriting as lang3 but still using StringBuffer (synchronized) looks like a missed opportunity.
Please use StringBuilder.
> Suggest audit for uses of StringBuffer in lang3 overall. No cause for it.

--
This message is automatically generated by JIRA.
If you think it was sent incorrectly, please contact your JIRA administrators
For more information on JIRA, see: http://www.atlassian.com/software/jira

Mime
View raw message