Java工具类:获取long型唯一ID
import java.text.SimpleDateFormat;import java.util.Date;
/**
* 获取long型唯一ID
*/
public class ID
{
private static long tmpID = 0;
private static boolean tmpIDlocked = false;
public static long getId()
{
long ltime = 0;
while (true)
{
if(tmpIDlocked == false)
{
tmpIDlocked = true;
//当前:(年、月、日、时、分、秒、毫秒)*10000
ltime = Long.valueOf(new SimpleDateFormat("yyMMddhhmmssSSS").format(new Date()).toString()) * 10000;
if(tmpID < ltime)
{
tmpID = ltime;
}
else
{
tmpID = tmpID + 1;
ltime = tmpID;
}
tmpIDlocked = false;
return ltime;
}
}
}
}
以上是 Java工具类:获取long型唯一ID 的全部内容, 来源链接: utcz.com/z/391305.html