Opened 23 months ago
Closed 23 months ago
#1454 closed defect (fixed)
SimpleDateFormat implementation is not thread-safe
Reported by: | Nicklas Nordborg | Owned by: | Nicklas Nordborg |
---|---|---|---|
Priority: | critical | Milestone: | Reggie v4.44 |
Component: | net.sf.basedb.reggie | Keywords: | |
Cc: |
Description
We use the java.text.SimpleDateFormat
implementation to format and parse dates whenever we need to convert to or from a java.util.Date
instance. In the Reggie
class we have several static variants for date with/without separators and with/without time.
When modifying the release exporter plug-in to a multi-threaded implementation (see #1453) I noticed a few cases with strange dates in the output files. As it turns out the SimpleDateFormat
is not thread-safe. When we are using the same instance with multiple threads at the same time the result can be mixed up.
Since Java 8 there is a newer implementation java.time.format.DateTimeFormatter
that is supposed to be thread-safe. However, it is uncertain that it behaves exactly the same way when parsing dates. The new implementation can also only be used with the new Date/Time API which require that we convert back and forth.
Another option is to use the Apache Commons Lang FastDateFormat
implementation. It has been designed to be a thread-safe drop-in replacement for the SimpleDateFormat
implementation. https://commons.apache.org/proper/commons-lang/apidocs/org/apache/commons/lang3/time/FastDateFormat.html
We already have that library included in BASE so it would be an easy switch.
Change History (5)
comment:1 by , 23 months ago
comment:5 by , 23 months ago
Resolution: | → fixed |
---|---|
Status: | new → closed |
In 7023: