Java / Using String
Is Java's SimpleDateFormat thread-safe?
No. SimpleDateFormat is not thread-safe, because it stores intermediate results in instance fields. So if one instance is used by two threads they can mess up each other's results.
It is recommended to create separate format instances for each thread. If multiple threads access a format concurrently, it must be synchronized externally.
DateTimeFormatter in Java 8 is immutable and thread-safe alternative to SimpleDateFormat.
More Related questions...