Aravind Yarram
Aravind Yarram

Reputation: 80194

Is Joiner thread safe?

Is google collections Joiner thread safe?

Upvotes: 16

Views: 2106

Answers (2)

Kevin Bourrillion
Kevin Bourrillion

Reputation: 40851

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 . . .

Upvotes: 29

daveb
daveb

Reputation: 76281

Its only state is a

  private final String separator;

So yes it's threadsafe.

Upvotes: 16

Related Questions