views:

124

answers:

2

Is google collections Joiner thread safe?

+5  A: 

Its only state is a

  private final String separator;

So yes it's threadsafe.

daveb
@Pangea - It's threadsafe now. If it is not documented as threadsafe, that may change in the future.
Robin
Also, since it's such a cheap object to create, why not create it locally when needed? Avoid sharing it between threads to begin with.
daveb
@Robin, that's prudent advice. Though documented or not, it would be awfully sociopathic of any library maintainer to change a class from threadsafe to not threadsafe after it's been released! We won't do that to you.
Kevin Bourrillion
@kevin Bourrillion - Thats good to hear. Of course I have met a few developers that might fall into that sociopathic category as well 8-)
Robin
+8  A: 

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 . . .
Kevin Bourrillion
Joiner doc has been fixed now.http://guava-libraries.googlecode.com/svn/trunk/javadoc/com/google/common/base/Joiner.html
Kevin Bourrillion