雪花算法生成id工具类

master
shijie 4 years ago
parent 972587b4f3
commit 8a0a7a8b86
  1. 45
      dq-framework-utils/src/main/java/com/daqing/framework/utils/SnowflakeIdUtils.java

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