I want to make following code thread safe. What is the best way to achieve it?
private static final DateFormat DATE_FORMAT = DateFormat.getDateTimeInstance(
The simplest solution would be:
synchronized public static final String eventTypeToDateTimeString(long timestamp) { return DATE_FORMAT.format(new Date(timestamp)); }
No need to use ThreadLocals since this is all in a static context.
ThreadLocal