If I have the following method; Is the call Calendar.getInstance()thread safe?
public Date currentTime() {
Date d = null;
synchronized(this){
d = Calendar.getInstance().getTime();
}
return d;
}
My understanding is Calendar.getInstance()not thread safe, so the following method cannot be thread safe. Is it correct?
public Date currentTime() {
return Calendar.getInstance().getTime();
}
I understand that Joda-Time is touted as best practice for date-based APIs, but here I am stuck with the standard java.util.Date/ Calendar classes.
source
share