Commit 97983e25 by hweeeeeei

Snowflake重复id问题; 解决思路:加synchronized 保证不会获取重复id

parent 269e0fc7
...@@ -11,7 +11,12 @@ public class SnowflakeUtil { ...@@ -11,7 +11,12 @@ public class SnowflakeUtil {
private static final Snowflake SNOWFLAKE = new Snowflake(1L, 1L); private static final Snowflake SNOWFLAKE = new Snowflake(1L, 1L);
public static Long getId() { /**
* 多线程中加synchronized 保证不会获取重复id
*
* @return
*/
public static synchronized Long getId() {
return SNOWFLAKE.nextId(); return SNOWFLAKE.nextId();
} }
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment