码迷,mamicode.com
首页 > 编程语言 > 详细

Java生成唯一的ID

时间:2016-02-05 01:56:15      阅读:186      评论:0      收藏:0      [点我收藏+]

标签:

public class UIDGenerator {
private static Date date = new Date();
private static StringBuilder buf = new StringBuilder();
private static int seq = 0;
private static final int ROTATION = 99999;
public static synchronized long next(){
if (seq > ROTATION) seq = 0;
buf.delete(0, buf.length());
date.setTime(System.currentTimeMillis());
String str = String.format("%1$tY%1$tm%1$td%1$tk%1$tM%1$tS%2$05d", date, seq++);
return Long.parseLong(str);
}
}

Java生成唯一的ID

标签:

原文地址:http://www.cnblogs.com/maybo/p/5182501.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!