From 8871f357490306f9a0dc75efc78442c0f9eb4ec2 Mon Sep 17 00:00:00 2001
From: ZhouXY108
Date: Fri, 27 Dec 2024 15:24:19 +0800
Subject: [PATCH] =?UTF-8?q?=E8=A1=A5=E5=85=85=20ID=20=E7=94=9F=E6=88=90?=
=?UTF-8?q?=E5=99=A8=E7=9A=84=20Javadoc=E3=80=82?=
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit
---
.../plusone/commons/util/IdGenerator.java | 14 ++++++++++---
.../zhouxy/plusone/commons/util/IdWorker.java | 21 ++++++++++++++++++-
.../commons/util/SnowflakeIdGenerator.java | 5 +----
3 files changed, 32 insertions(+), 8 deletions(-)
diff --git a/src/main/java/xyz/zhouxy/plusone/commons/util/IdGenerator.java b/src/main/java/xyz/zhouxy/plusone/commons/util/IdGenerator.java
index 66051a9..2bf8276 100644
--- a/src/main/java/xyz/zhouxy/plusone/commons/util/IdGenerator.java
+++ b/src/main/java/xyz/zhouxy/plusone/commons/util/IdGenerator.java
@@ -21,9 +21,17 @@ import java.util.Objects;
import java.util.UUID;
import java.util.concurrent.ConcurrentHashMap;
-import com.google.common.annotations.Beta;
-
-@Beta
+/**
+ * ID 生成器
+ *
+ *
+ * 生成 UUID 和 修改版雪花ID(Seata 版本)
+ *
+ *
+ * @see UUID
+ * @see IdWorker
+ * @author ZhouXY
+ */
public class IdGenerator {
// ===== UUID =====
diff --git a/src/main/java/xyz/zhouxy/plusone/commons/util/IdWorker.java b/src/main/java/xyz/zhouxy/plusone/commons/util/IdWorker.java
index e806cb2..20b59bc 100644
--- a/src/main/java/xyz/zhouxy/plusone/commons/util/IdWorker.java
+++ b/src/main/java/xyz/zhouxy/plusone/commons/util/IdWorker.java
@@ -24,7 +24,26 @@ import java.util.concurrent.atomic.AtomicLong;
import xyz.zhouxy.plusone.commons.exception.system.NoAvailableMacFoundException;
-
+/**
+ * Seata 提供的修改版雪花ID。
+ *
+ * 大体思路为:
+ *
+ * - 每个机器线程安全地生成序列,前面加上机器的id,这样就不会与其它机器的id相冲突。
+ * - 时间戳作为序列的“预留位”,它更像是应用启动时最开始的序列的一部分,在一个时间戳里生成 4096 个 id 之后,直接生成下一个时间戳的 id。
+ *
+ *
+ *
+ * 详情见以下介绍:
+ *
+ *
+ * @author ZhouXY
+ */
public class IdWorker {
/**
diff --git a/src/main/java/xyz/zhouxy/plusone/commons/util/SnowflakeIdGenerator.java b/src/main/java/xyz/zhouxy/plusone/commons/util/SnowflakeIdGenerator.java
index c89a4bc..da9f71e 100644
--- a/src/main/java/xyz/zhouxy/plusone/commons/util/SnowflakeIdGenerator.java
+++ b/src/main/java/xyz/zhouxy/plusone/commons/util/SnowflakeIdGenerator.java
@@ -18,12 +18,9 @@ package xyz.zhouxy.plusone.commons.util;
import java.util.concurrent.TimeUnit;
-import com.google.common.annotations.Beta;
-
/**
- * Twitter_Snowflake
+ * Twitter 版雪花算法
*/
-@Beta
public class SnowflakeIdGenerator {
// ==============================Fields===========================================