Find centralized, trusted content and collaborate around the technologies you use most.
Teams
Q&A for work
Connect and share knowledge within a single location that is structured and easy to search.
Joda-Time DateTimeFormatter类线程安全吗?一旦我得到一个实例DateTimeFormat.forPattern,它的各种解析方法可以被多个线程调用吗?DateTimeFormatter 的Javadocs没有提到线程安全。
DateTimeFormatter
DateTimeFormat.forPattern
是的,它是:
DateTimeFormat 是线程安全且不可变的,它返回的格式化程序也是如此。
Java 8 版本也是如此
实现要求:这个类是不可变的和线程安全的。
快速查看代码显示 中没有任何可变的共享状态DateTimeFormatter,这将使其成为线程安全的。
在检查 Java 的 java.time.format.DateTimeFormatter 线程安全性时,在谷歌的答案之上发现了这个问题
正如文档所述,Java 自己的 DateTimeFormatter 也是线程安全的:
这个类是不可变的和线程安全的