The class SimpleDateFormat
is not thread safe . I recently had problems with instances of class 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 do I 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 SimpleDateFormat
object with each call to the date formatting method (paying the price of the object's construction)?