I a writing a webapp in Java 1.6 and running it in tomcat. While I am not doing any explicit threading, I wonder about what is going on behind the scenes with Spring and Tomcat. Would I run into any issues using StringBuilder instead of StringBuffer?
If you are using a local variable you can safely use StringBuilder
. Each thread will get its own instance.
Usually Java EE components are not thread-safe by default, so unless you synchronize the blocks of code where you use the StringBuilder
, you'll experience race-conditions. So, you either have to take care of synchronization or use StringBuffer
.
Of course, as already mentioned if the StringBuilder
is a local variable, you don't have to worry about that.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With