Imagine a real concurrent scenario where StringBuffer should be used than StringBuilder?
I know the difference between StringBuffer and StringBuilder. read here!
And generally, as the javadoc says,
Where possible, it is recommended that this class be used in preference to StringBuffer as it will be faster under most implementations.
But, the javadoc of StringBuilder also says:
Instances of StringBuilder are not safe for use by multiple threads. If such synchronization is required then it is recommended that {@link java.lang.StringBuffer} be used
So, I am wondering, is the case that StringBuffer is preferred really existed? And as the mutable string is used mostly in a single thread, can anyone give me an concurrent real-world scenario that StringBuffer is preferred?
I know the difference between StringBuffer and StringBuilder. read here!
And generally, as the javadoc says,
Where possible, it is recommended that this class be used in preference to StringBuffer as it will be faster under most implementations.
But, the javadoc of StringBuilder also says:
Instances of StringBuilder are not safe for use by multiple threads. If such synchronization is required then it is recommended that {@link java.lang.StringBuffer} be used
So, I am wondering, is the case that StringBuffer is preferred really existed? And as the mutable string is used mostly in a single thread, can anyone give me an concurrent real-world scenario that StringBuffer is preferred?
No comments:
Post a Comment