[JAVA] DateFormat is not thread safe

As shown below, when I kept an instance of [DateFormat] 1 as a member variable and reused it, a crash report came up in Fabric.

class Util {

   companion object {
       private val sDateFormat = SimpleDateFormat("yyyy/MM/dd")

       fun convert(date: Date): String {
           return sDateFormat.format(date)
       }
   }

}

After investigating, it is an implementation that is called from multiple threads, and as shown in [Document] 1, it was changed to generate an instance every time.

class Util {

   companion object {
       fun convert(date: Date): String {
           return SimpleDateFormat("yyyy/MM/dd").format(date)
       }
   }

}

Recommended Posts

DateFormat is not thread safe
What is thread safe (with Java)
Yarn is not installed
Thread safe summary ~ Java ~
SimpleDateFormat is thread unsafe
"tx" is not bound error
Ruby # {} is not variable expansion
Java thread safe for you
[Rails] fields_for is not displayed
Uncaught ReferenceError: Vue is not defined
Ruby's attr_accessor is not an accessor
that? WebView (swift) is not working.
thread safe process in java language
rails AWS deployment is not reflected
Java Calendar is not a singleton.
Data is not registered in Rails.
Why Java Vector is not used
Java local variables are thread safe