Java Solaris Communities Sun Store Join SDN My Profile Why Join?
 
Bug Database
Bug Detail
Quick Lists
Top 25 Bugs
Top 25 RFE's
Recently Closed Bugs
Printable Page Printable Page


Bug Database
Bug ID: 4229798
Votes 0
Synopsis SimpleDateFormat is not thread safe
Category java:classes_text
Reported Against 1.2
Release Fixed
State 11-Closed, duplicate of 4093418, request for enhancement
Priority: 4-Low
Related Bugs 4093418
Submit Date 14-APR-1999
Description




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




- externally synchronize before calling format()
- implement your own DateFormatter
======================================================================
Evaluation
N/A
Comments
  
  Include a link with my name & email   


PLEASE NOTE: JDK6 is formerly known as Project Mustang