|
|
@ -5,8 +5,9 @@ import java.util.Set; |
|
|
|
|
|
|
|
|
|
|
|
/** |
|
|
|
/** |
|
|
|
* @Author: JCccc |
|
|
|
* @Author: JCccc |
|
|
|
* @Description: |
|
|
|
* @Description: 雪花算法生成id工具类 |
|
|
|
* @Date: created in 15:31 2019/6/12 |
|
|
|
* @Date: created in 15:31 2019/6/12 |
|
|
|
|
|
|
|
* @Modified By: gongsj. 修改为单例模式 modified in 11:50 2020/09/09 |
|
|
|
*/ |
|
|
|
*/ |
|
|
|
public class SnowflakeIdUtils { |
|
|
|
public class SnowflakeIdUtils { |
|
|
|
// ==============================Fields===========================================
|
|
|
|
// ==============================Fields===========================================
|
|
|
@ -174,27 +175,27 @@ public class SnowflakeIdUtils { |
|
|
|
return SnowflakeIdUtils.getInstance().nextId(); |
|
|
|
return SnowflakeIdUtils.getInstance().nextId(); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
public static void main(String[] args) { |
|
|
|
// public static void main(String[] args) {
|
|
|
|
|
|
|
|
//
|
|
|
|
SnowflakeIdUtils snowflakeIdUtils = SnowflakeIdUtils.getInstance(); |
|
|
|
// SnowflakeIdUtils snowflakeIdUtils = SnowflakeIdUtils.getInstance();
|
|
|
|
|
|
|
|
//
|
|
|
|
// for (int i = 0; i < 20; i++) {
|
|
|
|
//// for (int i = 0; i < 20; i++) {
|
|
|
|
// System.out.println(snowflakeIdUtils.nextId());
|
|
|
|
//// System.out.println(snowflakeIdUtils.nextId());
|
|
|
|
// }
|
|
|
|
//// }
|
|
|
|
// System.out.println("-+-+-+-+-+-+-+-+-+-+-+-+-+-");
|
|
|
|
//// System.out.println("-+-+-+-+-+-+-+-+-+-+-+-+-+-");
|
|
|
|
// for (int i = 0; i < 20; i++) {
|
|
|
|
//// for (int i = 0; i < 20; i++) {
|
|
|
|
// System.out.println(SnowflakeIdUtils.getInstance().nextId());
|
|
|
|
//// System.out.println(SnowflakeIdUtils.getInstance().nextId());
|
|
|
|
// }
|
|
|
|
//// }
|
|
|
|
// Set<Long> set2 = new HashSet<>();
|
|
|
|
//// Set<Long> set2 = new HashSet<>();
|
|
|
|
|
|
|
|
//// for (int i = 0; i < 1000000; i++) {
|
|
|
|
|
|
|
|
//// set2.add(snowflakeIdUtils.nextId());
|
|
|
|
|
|
|
|
//// }
|
|
|
|
|
|
|
|
//// System.out.println(set2.size());
|
|
|
|
|
|
|
|
////
|
|
|
|
|
|
|
|
// Set<Long> set = new HashSet<>();
|
|
|
|
// for (int i = 0; i < 1000000; i++) {
|
|
|
|
// for (int i = 0; i < 1000000; i++) {
|
|
|
|
// set2.add(snowflakeIdUtils.nextId());
|
|
|
|
// set.add(SnowflakeIdUtils.getRandomid());
|
|
|
|
|
|
|
|
// }
|
|
|
|
|
|
|
|
// System.out.println(set.size());
|
|
|
|
// }
|
|
|
|
// }
|
|
|
|
// System.out.println(set2.size());
|
|
|
|
|
|
|
|
//
|
|
|
|
|
|
|
|
Set<Long> set = new HashSet<>(); |
|
|
|
|
|
|
|
for (int i = 0; i < 1000000; i++) { |
|
|
|
|
|
|
|
set.add(SnowflakeIdUtils.getRandomid()); |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
System.out.println(set.size()); |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
} |
|
|
|
} |