2
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 5 years have passed since last update.

DateFormatはスレッドセーフじゃない

2
Posted at

下記のようにDateFormatのインスタンスをメンバ変数として保持して使いまわしていたところ、Fabricにクラッシュレポートが上がってきました。

class Util {

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

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

}

調査したところ複数スレッドから呼ばれる実装になっており、ドキュメントにもあるように毎度インスタンスを生成するように変更して対応しました。

class Util {

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

}
2
0
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
2
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?