# est-spi-uuid **Repository Path**: est-spi/uuid ## Basic Information - **Project Name**: est-spi-uuid - **Description**: No description available - **Primary Language**: Java - **License**: Not specified - **Default Branch**: master - **Homepage**: None - **GVP Project**: No ## Statistics - **Stars**: 0 - **Forks**: 0 - **Created**: 2026-03-15 - **Last Updated**: 2026-03-21 ## Categories & Tags **Categories**: Uncategorized **Tags**: None ## README # EST SPI UUID [English Version](README.en.md) ## EST SPI UUID模块 est-spi-uuid 是 EST SPI 框架的UUID模块,提供了多种UUID生成方式,包括JDK UUID和雪花算法。 ### 核心功能 #### UuidGenerator - UUID生成器接口 UUID生成器的统一接口,提供字符串和字节数组两种生成方式。 #### JdkUuidGenerator - JDK UUID实现 基于JDK的UUID.randomUUID()实现(单例)。 #### SnowflakeGenerator - 雪花算法实现 Twitter雪花算法的分布式ID生成实现,支持自定义工作节点和数据中心ID。 ### 快速开始 #### 使用JdkUuidGenerator ```java import ltd.idcu.est.spi.uuid.JdkUuidGenerator; import ltd.idcu.est.spi.uuid.UuidGenerator; public class Example { public static void main(String[] args) { UuidGenerator generator = JdkUuidGenerator.getInstance(); String uuid = generator.generate(); System.out.println("UUID: " + uuid); byte[] bytes = generator.generateBytes(); System.out.println("UUID Bytes Length: " + bytes.length); } } ``` #### 使用SnowflakeGenerator(默认实例) ```java import ltd.idcu.est.spi.uuid.SnowflakeGenerator; import ltd.idcu.est.spi.uuid.UuidGenerator; public class Example { public static void main(String[] args) { UuidGenerator generator = SnowflakeGenerator.getInstance(); String id = generator.generate(); System.out.println("Snowflake ID: " + id); byte[] bytes = generator.generateBytes(); System.out.println("ID Bytes Length: " + bytes.length); } } ``` #### 使用SnowflakeGenerator(自定义配置) ```java import ltd.idcu.est.spi.uuid.SnowflakeGenerator; public class Example { public static void main(String[] args) { long workerId = 5; long dataCenterId = 5; SnowflakeGenerator generator = new SnowflakeGenerator(workerId, dataCenterId); long id = generator.generateId(); System.out.println("Snowflake ID: " + id); } } ``` #### 批量生成ID ```java import ltd.idcu.est.spi.uuid.SnowflakeGenerator; import java.util.HashSet; import java.util.Set; public class Example { public static void main(String[] args) { SnowflakeGenerator generator = SnowflakeGenerator.getInstance(); Set ids = new HashSet<>(); int count = 10000; long startTime = System.currentTimeMillis(); for (int i = 0; i < count; i++) { long id = generator.generateId(); ids.add(id); } long endTime = System.currentTimeMillis(); System.out.println("Generated " + count + " IDs in " + (endTime - startTime) + "ms"); System.out.println("All IDs are unique: " + (ids.size() == count)); } } ``` ### 雪花算法说明 雪花算法生成64位ID结构: - 1位:符号位(不使用) - 41位:时间戳(毫秒级,从2021-01-01 00:00:00开始) - 10位:工作机器ID(5位数据中心ID + 5位工作节点ID) - 12位:序列号(每毫秒4096个ID) ### Maven 依赖 ```xml ltd.idcu.est.spi est-spi-uuid 1.0.0 ``` ### 许可证 MIT License