Is google collections Joiner thread safe?
Unlike StringBuffer methods (like append() ) which are synchronized, methods of StringJoiner (like add() ) are not synchronized . Thus it is not thread-safe.
Save this answer. Show activity on this post. Thread safety becomes a concern if there is at least a single entry point which can be accessed by multiple threads. If a piece of code is accessed by multiple threads and is calling other method/class/etc., then all this code tree becomes vulnerable.
Threadsafe Collections. The collection interfaces in Java – List, Set, Map – have basic implementations that are not threadsafe. The implementations of these that you've been used to using, namely ArrayList, HashMap, and HashSet, cannot be used safely from more than one thread.
Yes! We're not about to repeat the mistakes of SimpleDateFormat
. :-)
Joiner
needs to receive a similar documentation upgrade to what its sister class Splitter
got, which says:
* <p><b>Warning: splitter instances are always immutable</b>; a configuration
* method such as {@code omitEmptyStrings} has no effect on the instance it
* is invoked on! You must store and use the new splitter instance returned by
* the method. This makes splitters thread-safe, and safe to store as {@code
* static final} constants . . .
Its only state is a
private final String separator;
So yes it's threadsafe.
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