JDK-4229798 : SimpleDateFormat is not thread safe
  • Type: Enhancement
  • Component: core-libs
  • Sub-Component: java.text
  • Affected Version: 1.2.0
  • Priority: P4
  • Status: Closed
  • Resolution: Duplicate
  • OS: generic
  • CPU: generic
  • Submitted: 1999-04-14
  • Updated: 1999-04-15
  • Resolved: 1999-04-15
Related Reports
Duplicate :  
Description

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) 
======================================================================

Comments
WORK AROUND Name: vi73552 Date: 04/14/99 - externally synchronize before calling format() - implement your own DateFormatter ======================================================================
11-06-2004