String buffers are safe for use by multiple threads.

The methods are synchronized where necessary

so that all the operations on any particular instance behave

as if they occur in some serial order that is consistent with the order of the method calls

made by each of the individual threads involved.

... 중략

As of release JDK 5,

this class has been supplemented with an equivalent class

designed for use by a single thread, StringBuilder.

The StringBuilder class should generally be used in preference to this one,

as it supports all of the same operations but it is faster,

as it performs no synchronization.


즉, 결론은

StringBuffer

 - Tthread safe가 보장되도록 처리가 되었기 때문에여러 thread에 의해 공유되어야 하는 경우에 사용하고,


StringBuilder

 - 여러 thread에 의해 method내의 local로 사용되는 것처럼 공유될 필요가 없는 상황에서

   속도 향상을 위해 사용

+ Recent posts