Joiner线程安全吗?

Ara*_*ram 16 java thread-safety guava

谷歌收藏Joiner线程安全吗?

Kev*_*ion 28

是! 我们不打算重蹈覆辙SimpleDateFormat.:-)

Joiner需要获得类似的文档升级到其姐妹班级Splitter得到的,其中说:

* <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 . . .
Run Code Online (Sandbox Code Playgroud)

  • Joiner doc现已修复.http://guava-libraries.googlecode.com/svn/trunk/javadoc/com/google/common/base/Joiner.html (8认同)

dav*_*veb 16

它唯一的状态是

  private final String separator;
Run Code Online (Sandbox Code Playgroud)

所以是的,它是线程安全的.

  • @Robin,这是谨慎的建议.虽然有文件记录或未记录,但任何图书馆维护者在发布之后将类从线程安全更改为线程安全是非常反社会的!我们不会那样对你. (7认同)
  • @Pangea - 现在是线程安全的.如果没有记录为线程安全,那么将来可能会发生变化. (2认同)