I have the following function:
public static int getDiffHour(Date first) {
int hoursBetween = Hours.hoursBetween(new LocalDate(first), new LocalDate()).getHours();
return hoursBetween;
}
I am trying to get difference in hours between two dates.
Here is my Traceview:
The function is taking crazy amounts of time and resource to execute - what do I miss here. My service is getting killed on 5.0.1 due to this enormous CPU time taken by this function.
Digging down deeper, I find that 99% of the CPU time is taken by LocalDate init. Is there a way I can avoid that and supply a date precalculated?
This issue might have been solved with the newest Joda-Time-release v2.6 because the class initialization of class DateTimeZone
(where you observe huge amounts of time spent) no longer calls the method setProvider0()
, see also this commit.