c#实现分组服务器,单一无重复生成ID

 1 class Program
 2     {
 3         static void Main(string[] args)
 4         {
 5             List<Thread> threads = new List<Thread>();
 6             getID();
 7             Console.WriteLine("重复次数:" + ccount);
 8             Console.ReadLine();
 9         }
10 
11         public static void getID()
12         {
13             for (int j = 0; j < 20; j++)
14             {
15                 for (int i = 0; i < 99999; i++)
16                 {
17                     // GetDate();
18                     Console.WriteLine(GetDate());
19                 }
20                 Thread.Sleep(980);
21             }
22         }
23 
24         static int serverID = 99;
25         static ulong ID = 1;
26         static HashSet<string> longset = new HashSet<string>();
27         static int ccount = 0;
28 
29         public static string GetDate()
30         {
31             lock (typeof(ulong))
32             {
33                 if (ID + 1 > 99999)
34                 {
35                     ID = 0;
36                 }
37                 ID++;
38                 string _ulong = serverID + "" + System.DateTime.Now.ToString("yyMMddHHmmss") + ("" + ID).PadLeft(5, '0');
39                 if (longset.Contains(_ulong))
40                 {
41                     ccount++;
42                 }
43                 longset.Add(_ulong);
44                 return _ulong;
45             }
46         }
47     }

该程序用于生成的ID太强规则可言的,可实现分布式生成ID,在合并数据是无重复ID~!目前支持99组服务器同时运行,每秒9999个ID生成~!

跪求保留标示符
/**
 * @author: Troy.Chen(失足程序员, 15388152619)
 * @version: 2021-07-20 10:55
 **/

C#版本代码 vs2010及以上工具可以

java 开发工具是netbeans 和 idea 版本,只有项目导入如果出现异常,请根据自己的工具调整


提供免费仓储。
最新的代码地址:↓↓↓
https://gitee.com/wuxindao

觉得我还可以,打赏一下吧,你的肯定是我努力的最大动力
    
原文地址:https://www.cnblogs.com/shizuchengxuyuan/p/4326419.html