can you please tell me if the following code is thread safe and how I could test it:
private static final SimpleDateFormat sdf = new SimpleDateFormat("MMddHHmmss");
Calendar cal = new GregorianCalendar();
TimeZone timezone = cal.getTimeZone();
AppCalendar qCal = new AppCalendar(timezone);
qCal.setDateToday();
qCal.setTimeNow();
}
public static String createTempName(final TimeZone timeZone) {
final AppCalendar calendar = new AppCalendar(timeZone);
calendar.setDateToday();
calendar.setTimeNow();
synchronized (sdf) {
return sdf.format(calendar.getTime());
}
}
I mention that my code runs on JVM 7 and I have to use Date types provided by this context. Unfortunately not being able to use thred save LocalDate from Java 8. I am using the string returned from method createTempName as a unique key in database column. appCalendar is class that extends java.util.GregorianCalendar.
Sincerely,