timestamper.java

来自「这是一款最新的野蔷薇论坛源码,有需要的朋友可以尽情下载」· Java 代码 · 共 35 行

JAVA
35
字号
/* 
 * Created on 2006-2-25
 * Last modified on 2006-2-25
 * Powered by YeQiangWei.com
 */
package com.yeqiangwei.club.cache;

public final class Timestamper {
	
	private static short counter = 0;
	private static long time;
	private static final int BIN_DIGITS = 12;
	public static final short ONE_MS = 1<<BIN_DIGITS;
	
	public static long next() {
		synchronized(Timestamper.class) {
			long newTime = System.currentTimeMillis() << BIN_DIGITS;
			if (time<newTime) {
				time = newTime;
				counter = 0;
			}
			else if (counter < ONE_MS - 1 ) {
				counter++;
			}
			
			return time + counter;
		}
	}

	private Timestamper() {}
}



⌨️ 快捷键说明

复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?