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: 4175308
Votes 0
Synopsis java.text.SimpleDateFormat is not thread safe.
Category java:classes_text
Reported Against 1.1.6
Release Fixed
State 11-Closed, duplicate of 4093418, bug
Priority: 4-Low
Related Bugs 4093418
Submit Date 22-SEP-1998
Description




Just create a program having lots of threads
which format dates with:

  dateFormatter.format(new Date());

When I use the format pattern:

  [dd/MMM/yyyy:HH:mm:ss z]

I get formatted dates like the following:

  [05/May/1998:14:46:33 PDT]
  [05/May/1998:14:46:34 PDT]
  [0005/May/1998:14:46:34 PDT] 
  [05/May/1998:14:46:34 PDT]
  [05/May/1998:14:46:34 PDT]
  [0005/May/1998:14:46:0034 PDT]
  [0005/May/1998:14:46:0034 PDT]
  [05/May/1998:14:46:0034 PDT]
  [0005/May/1998:14:46:0034 PDT]
  [0005/May/1998:14:0046:34 PDT]
  [05/May/1998:14:0046:34 PDT]

(with lots of extra zeros here and there).
(Review ID: 29763)
======================================================================
Work Around




The workaround is to put a synchronized block
around every place where I format dates with
their common formatter:

  synchronized (dateFormatter) {
    dateFormatter.format(new Date());
  }

Why not simply make date formatting thread safe
in the same way you've just fixed the problem
with number formatting (Bug Id 4101500).
======================================================================
Evaluation
N/A
Comments
  
  Include a link with my name & email   


PLEASE NOTE: JDK6 is formerly known as Project Mustang