15
The class SimpleDateFormat
is not thread safe. I recently had problems with class instances SimpleDateFormat
in static context being used by multiple threads concurrently in a web application.
private static final DateFormat df = new SimpleDateFormat("dd/MM/yyyy");
How should I proceed to ensure synchronization / competition with the minimum of overhead? For example, I should use syncronized
, create an instance ThreadLocal
or who knows how to create a new instance of the object SimpleDateFormat
each call to the date formatting method (paying the price of constructing the object)?
Drop that SDT and use JODA!
– Daniel C. Sobral