IDUtils.java
575 Bytes
package cn.com.polysoft.utils;
/**
* id生成策略
* @author weijixiang
* @Description
* @date 2019/7/31.
*/
public class IDUtils {
private static byte[] lock = new byte[0];
/**
* 5位数
*/
private final static long w = 100000;
/**
* 使用时间戳+5位随机数作为主键ID
* @return
*/
public static String createID() {
long r = 0;
synchronized (lock) {
r = (long) ((Math.random() + 1) * w);
}
return System.currentTimeMillis() + String.valueOf(r).substring(1);
}
}