JDK-4175308 : java.text.SimpleDateFormat is not thread safe.
  • Type: Bug
  • Component: core-libs
  • Sub-Component: java.text
  • Affected Version: 1.1.6
  • Priority: P4
  • Status: Closed
  • Resolution: Duplicate
  • OS: windows_nt
  • CPU: x86
  • Submitted: 1998-09-22
  • Updated: 1998-10-28
  • Resolved: 1998-10-28
Related Reports
Duplicate :  
Description

Name: nl37777			Date: 09/21/98


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

Comments
WORK AROUND Name: nl37777 Date: 09/21/98 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). ======================================================================
11-06-2004