Synchronizing access to SimpleDateFormat

前端 未结 9 1470
名媛妹妹
名媛妹妹 2020-12-02 06:56

The javadoc for SimpleDateFormat states that SimpleDateFormat is not synchronized.

\"Date formats are not synchronized. It is recommended to create

9条回答
  •  一整个雨季
    2020-12-02 07:13

    I would say, create a simple wrapper-class for SimpleDateFormat that synchronizes access to parse() and format() and can be used as a drop-in replacement. More foolproof than your option #2, less cumbersome than your option #3.

    Seems like making SimpleDateFormat unsynchronized was a poor design decision on the part of the Java API designers; I doubt anyone expects format() and parse() to need to be synchronized.

提交回复
热议问题