Is Joda-Time DateTimeFormatter class thread safe?
Asked Answered
G

3

64

Is the Joda-Time DateTimeFormatter class thread safe? Once I get an instance from DateTimeFormat.forPattern, can its various parse methods be called by multiple threads? DateTimeFormatter's Javadocs makes no mention of thread safety.

Goeselt answered 22/9, 2012 at 2:49 Comment(0)
H
87

Yes, it is:

DateTimeFormat is thread-safe and immutable, and the formatters it returns are as well.

and so is the Java 8 version

Implementation Requirements: This class is immutable and thread-safe.

Herdic answered 22/9, 2012 at 2:52 Comment(1)
And so is the Java8 one as well. See docs.oracle.com/javase/8/docs/api/java/time/format/…Biased
O
14

A quick look at the code shows there isn't any mutable shared state in DateTimeFormatter, which would make it thread safe.

Oared answered 22/9, 2012 at 2:53 Comment(1)
Nitpick: A quick look at the code does not necessarily show how the code will be changed in the next point release. It's always better to have an explicit guarantee in the documented API (of course, additionally checking the code cannot hurt).Ingra
O
5

Found this question on top of google's answers when checking for Java's java.time.format.DateTimeFormatter thread safety

Java's own DateTimeFormatter is also thread-safe, as the documentation states:

This class is immutable and thread-safe

Ohalloran answered 28/6, 2016 at 7:6 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.