7077172: KerberosTime does not take into account system clock adjustement
Reviewed-by: valeriep
This commit is contained in:
parent
29ad75ff83
commit
9111a2a768
@ -68,8 +68,8 @@ public class KerberosTime implements Cloneable {
|
|||||||
private int microSeconds; // the last three digits of the microsecond value
|
private int microSeconds; // the last three digits of the microsecond value
|
||||||
|
|
||||||
// The time when this class is loaded. Used in setNow()
|
// The time when this class is loaded. Used in setNow()
|
||||||
private static final long initMilli = System.currentTimeMillis();
|
private static long initMilli = System.currentTimeMillis();
|
||||||
private static final long initMicro = System.nanoTime() / 1000;
|
private static long initMicro = System.nanoTime() / 1000;
|
||||||
|
|
||||||
private static long syncTime;
|
private static long syncTime;
|
||||||
private static boolean DEBUG = Krb5.DEBUG;
|
private static boolean DEBUG = Krb5.DEBUG;
|
||||||
@ -212,9 +212,22 @@ public class KerberosTime implements Cloneable {
|
|||||||
}
|
}
|
||||||
|
|
||||||
public void setNow() {
|
public void setNow() {
|
||||||
long microElapsed = System.nanoTime() / 1000 - initMicro;
|
long newMilli = System.currentTimeMillis();
|
||||||
setTime(initMilli + microElapsed/1000);
|
long newMicro = System.nanoTime() / 1000;
|
||||||
microSeconds = (int)(microElapsed % 1000);
|
long microElapsed = newMicro - initMicro;
|
||||||
|
long calcMilli = initMilli + microElapsed/1000;
|
||||||
|
if (calcMilli - newMilli > 100 || newMilli - calcMilli > 100) {
|
||||||
|
if (DEBUG) {
|
||||||
|
System.out.println("System time adjusted");
|
||||||
|
}
|
||||||
|
initMilli = newMilli;
|
||||||
|
initMicro = newMicro;
|
||||||
|
setTime(newMilli);
|
||||||
|
microSeconds = 0;
|
||||||
|
} else {
|
||||||
|
setTime(calcMilli);
|
||||||
|
microSeconds = (int)(microElapsed % 1000);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public int getMicroSeconds() {
|
public int getMicroSeconds() {
|
||||||
|
Loading…
x
Reference in New Issue
Block a user