Uploaded image for project: 'JDK'
  1. JDK
  2. JDK-4229798

SimpleDateFormat is not thread safe

XMLWordPrintable

    • Icon: Enhancement Enhancement
    • Resolution: Duplicate
    • Icon: P4 P4
    • None
    • 1.2.0
    • core-libs
    • generic
    • generic



      Name: vi73552 Date: 04/14/99


      1) access java.text.SimpleDateFormat.format(java.util.Date) from
      multiple threads
      5) looking at the source code of the classes it is obvious
      that this is not going to work for multiple threads, because the
      method format() manipulates object members.

      In my professional opinion the format() method should leave the
      state of the DateFormat object unchanged. Members must only be
      accessed read-only. In C++ you would declare the method const.
      I think there is a mismatch between the semantics the class
      maintains to the outside and the way it is implemented
      internally. Maintaining a DateFormat object per thread is
      unnecessary overhead, and in our case [a system wide logging
      utility accessed from multiple clients] it's unreasonable.
      It would be very efficient to set up an immutable DateFormat
      object once, and then access it *unsynchronized* from many
      threads, each of which getting their dates formatted
      (Review ID: 56578)
      ======================================================================

            Unassigned Unassigned
            vasya Vassili Igouchkine (Inactive)
            Votes:
            0 Vote for this issue
            Watchers:
            0 Start watching this issue

              Created:
              Updated:
              Resolved:
              Imported:
              Indexed: