1 package org.hibernate.cache; 3 4 9 public final class Timestamper { 10 private static short counter = 0; 11 private static long time; 12 private static final int BIN_DIGITS = 12; 13 public static final short ONE_MS = 1<<BIN_DIGITS; 14 15 public static long next() { 16 synchronized(Timestamper.class) { 17 long newTime = System.currentTimeMillis() << BIN_DIGITS; 18 if (time<newTime) { 19 time = newTime; 20 counter = 0; 21 } 22 else if (counter < ONE_MS - 1 ) { 23 counter++; 24 } 25 26 return time + counter; 27 } 28 } 29 30 private Timestamper() {} 31 } 32 33 34 35 36 37 38 | Popular Tags |