In most cases, synchronization is not only not required, but also gives readers a code of incorrect information, if you nevertheless use it: namely, the reader could assume that synchronization is required where it is not really.
Using StringBuilder instead advertises the fact that you do not expect access to cross-threads.
In fact, streaming data should always be done through well-defined communication channels in any case, and not just by accessing a synchronized string buffer. Therefore, I would recommend always using a different solution, even if a StringBuffer seems appropriate at first glance.
Konrad Rudolph Jul 21 2018-11-11T00: 00Z
source share