Is google collections Joiner thread safe?
+5
A:
Its only state is a
private final String separator;
So yes it's threadsafe.
daveb
2010-03-03 20:53:12
@Pangea - It's threadsafe now. If it is not documented as threadsafe, that may change in the future.
Robin
2010-03-03 21:26:37
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
2010-03-03 21:47:35
@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
2010-03-03 23:52:05
@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
2010-03-04 14:08:41
+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
2010-03-03 23:48:39
Joiner doc has been fixed now.http://guava-libraries.googlecode.com/svn/trunk/javadoc/com/google/common/base/Joiner.html
Kevin Bourrillion
2010-05-04 00:21:29