public class ObjectId extends Object
1. Time 时间戳。 2. Machine 所在主机的唯一标识符,一般是机器主机名的散列值。 3. PID 进程ID。确保同一机器中不冲突 4. INC 自增计数器。确保同一秒内产生objectId的唯一性。
参考:http://blog.csdn.net/qxc1281/article/details/54021882
| 限定符和类型 | 字段和说明 |
|---|---|
private static int |
machine
机器信息
|
private static AtomicInteger |
nextInc
线程安全的下一个随机数,每次生成自增+1
|
| 构造器和说明 |
|---|
ObjectId() |
| 限定符和类型 | 方法和说明 |
|---|---|
private static int |
getMachinePiece()
获取机器码片段
|
private static int |
getProcessPiece()
获取进程码片段
|
static boolean |
isValid(String s)
给定的字符串是否为有效的ObjectId
|
static String |
next()
获取一个objectId用下划线分割
|
static String |
next(boolean withHyphen)
获取一个objectId
|
static byte[] |
nextBytes()
获取一个objectId的bytes表现形式
|
private static final AtomicInteger nextInc
private static final int machine
public static boolean isValid(String s)
s - 字符串public static byte[] nextBytes()
public static String next()
public static String next(boolean withHyphen)
withHyphen - 是否包含分隔符private static int getMachinePiece()
private static int getProcessPiece()
Copyright © 2020. All rights reserved.