Imagine i have a proccess that creates 1000 entities each second. for each of these entities i call the setter :
newEntity.setDate(new Date());
1) Is it possible that 2 entities will recieve the same date? or is it safe to assume that i do get a unique identifier effect for the date field?
2) If the answer to question #1 is :"yes" - let's make a minor tweak: lets create a function:
public static synchronized Date getDate() {
return new Date();
}
will it work now?
newEntity.setDate(getDate());
3) what about
System.nanoTime()?
EDIT 4) what about :
public static synchronized Date getDate() {
Thread.Sleep(1000);
return new Date();
}
thanks.