JAVA 时间戳+随机数生成唯一ID

来源:互联网 发布:python time 精确到秒 编辑:程序博客网 时间:2024/05/29 18:28
/**    * @Title: IDUtils.java  * @Package com.createid  * @Description: TODO(用一句话描述该文件做什么)  * @author Aaron·Li    * @date 2017年9月20日 上午11:51:31  * @version V1.0    */package com.yitianyike.utils;/** * @author Aaron·Li * @date 2017年9月20日 上午11:51:31 */public class IDUtils {private static byte[] lock = new byte[0];// 位数,默认是8位private final static long w = 100000000;public static String createID() {long r = 0;synchronized (lock) {r = (long) ((Math.random() + 1) * w);}return System.currentTimeMillis() + String.valueOf(r).substring(1);}}

阅读全文
0 0