Methods Summary |
---|
public long | getActualTime()Returns the actual/correct time. Same as calling System.currentTimeMillis()
nextIndex = 1 - index;
time[nextIndex] = System.currentTimeMillis();
index = nextIndex;
return time[index];
|
public long | getDelay()Returns the delay
return sleepTime;
|
public long | getTime()Returns the approximate time. Returns the time that was updated
(utmost) 'delay' milliseconds earlier.
return time[index];
|
public static void | main(java.lang.String[] args)
int count = 100000000;
long time=0, t1=0, t2 = 0;
t1 = System.currentTimeMillis();
for (int i=0; i<count; i++) {
time = System.currentTimeMillis();
}
t2 = System.currentTimeMillis();
//Bug System.out.println("sys.currentTimeMillis() took: " + ((t2 - t1) / 1000.0) + " seconds " + time);
_logger.log(Level.FINE,"sys.currentTimeMillis() took: " + ((t2 - t1) / 1000.0) + " seconds " + time);
t1 = System.currentTimeMillis();
ApproximateClock clock = new ApproximateClock(3000);
for (int i=0; i<count; i++) {
time = clock.getTime();
}
t2 = System.currentTimeMillis();
//Bug System.out.println("clcok.getTime() took: " + ((t2 - t1) / 1000.0) + " seconds " + time);
_logger.log(Level.FINE,"clock.getTime() took: " + ((t2 - t1) / 1000.0) + " seconds " + time);
|
public final void | run()The thread's run method to update the time periodically
while (true) {
try {
getActualTime();
Thread.sleep(sleepTime);
} catch (InterruptedException inEx) {
break;
}
}
|
public void | setDelay(long delay)Set the delay for updating the time.
sleepTime = (delay < 1) ? 1 : delay;
|