Alternatives to FastDateFormat for efficient date parsing?

后端 未结 6 939
-上瘾入骨i
-上瘾入骨i 2021-02-05 04:29

Well aware of performance and thread issues with SimpleDateFormat, I decided to go with FastDateFormat, until I realized that FastDateFormat

6条回答
  •  南笙
    南笙 (楼主)
    2021-02-05 05:35

    The 'problem' with SimpleDateFormat is not performance, its thread safety.

    If you have thousands of threads and synchronizing is not an issue use synchronized (you can also pool the instances to alleviate this a little)

    If you have a reasonable amount of threads the recommended way is to have a separate instance for each SimpleDateFormat.

    UPDATE

    As of Java 8, just use DateTimeFormatter. It is immutable, thread safe, faster, and more flexible. (It also offers nice features like default patterns for ISO-8601 date/time strings.)

提交回复
热议问题