-
Notifications
You must be signed in to change notification settings - Fork 18
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Bring out the difference in usage of StringBuilder and StringBuffer #29
Comments
Thank you for your feedback! We’ll look into it and come back to you if we have any questions. |
Dear @vadimklimov - thanks so much for your valueable feedback. We've made adjustments which will hopefully cover your use case. Please wait for the next publications of the documentation! Best Annika |
Thank you for your valuable feedback contribution, @vadimklimov! So that we can recognize your contribution in SAP Community, please tell us your SAP Community profile URL in a reply to this comment; don't include any other text, just the URL on its own, like this:
Thanks! |
@AnnikaGonnermann, thank you for your time and efforts when assessing and evaluating this proposal, and for accepting it. And a special thanks to you and the entire team for your openness and collaboration with the community on this initiative - this is very much appreciated. |
Issue description
The documentation contains the following recommendations:
The usage of classes that offer mutability (such as
StringBuilder
andStringBuffer
) instead of immutableString
objects for string literals that are subject to frequent manipulations/changes makes great sense. Though while reading this recommendation, it may not be immediately obvious what use cases are forStringBuilder
compared withStringBuffer
, and these two may be considered to be interchangeable.It may be worth highlighting the difference between
StringBuilder
andStringBuffer
. While both are used to create mutable objects that can be further stringified,StringBuffer
's public methods are synchronized, leading to thread safety ofStringBuffer
objects in a multi-threaded environment, whereasStringBuilder
is not thread-safe. On the other hand, thread safety comes at the cost of performance overhead. As a result, it shall be evaluated and assessed if thread safety / synchronization is truly required - if so,StringBuffer
shall be considered, and if thread safety is not a concern, performance can be further optimized by usingStringBuilder
instead.While SAP Cloud Integration runtime is a multi-threaded environment, I can only come up with a handful of relevant use cases where synchronization is required for string representations that are manipulated in Groovy scripts, which makes me think that
StringBuilder
shall have a broader range of use cases thanStringBuffer
in scripts developed in SAP Cloud Integration.Feedback Type (Optional)
clarity
Page Title on SAP Help Portal (prefilled)
General Scripting Guidelines
Page URL on SAP Help Portal (prefilled)
https://help.sap.com/docs/cloud-integration/sap-cloud-integration/general-scripting-guidelines
The text was updated successfully, but these errors were encountered: