/** * This method returns a Date object that is accurate to within one second. If a thread calls this * method to get a Date and it's been less than 1 second since a new Date was created, this method * simply gives out the same Date again so that the system doesn't spend time creating Date * objects unnecessarily. * * @return Date */ public static Date getDate() { // Only create a new Date once per second, max. long systime = System.currentTimeMillis(); AccessDateStruct struct = currentDateStruct.get(); if ((systime - struct.currentDate.getTime()) > 1000) { struct.currentDate.setTime(systime); struct.currentDateString = null; } return struct.currentDate; }
private static AccessDateStruct getAccessDateStruct(Date date) { AccessDateStruct struct = currentDateStruct.get(); if (struct.currentDateString == null) { StringBuilder current = new StringBuilder(32); current.append('['); current.append(struct.dayFormatter.format(date)); current.append('/'); current.append(lookup(struct.monthFormatter.format(date))); current.append('/'); current.append(struct.yearFormatter.format(date)); current.append(':'); current.append(struct.timeFormatter.format(date)); current.append(' '); current.append(AccessTimeUtil.getTimeZone()); current.append(']'); struct.currentDateString = current.toString(); } return struct; }