You can not select more than 25 topics Topics must start with a chinese character,a letter or number, can include dashes ('-') and can be up to 35 characters long.

GenTest.cs 1.4 kB

4 years ago
4 years ago
4 years ago
4 years ago
4 years ago
4 years ago
4 years ago
4 years ago
4 years ago
4 years ago
4 years ago
4 years ago
4 years ago
4 years ago
4 years ago
12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849
  1. using System;
  2. using System.Collections;
  3. using System.Collections.Generic;
  4. using System.Text;
  5. using System.Threading;
  6. using System.Threading.Tasks;
  7. using Yitter.IdGenerator;
  8. namespace Yitter.OrgSystem.TestA
  9. {
  10. public class GenTest
  11. {
  12. private IIdGenerator IdGen;
  13. private Hashtable ids = new Hashtable();
  14. public IList<long> idList = new List<long>();
  15. private int GenIdCount;
  16. private int WorkerId;
  17. public GenTest(IIdGenerator idGen, int genIdCount, int workerId)
  18. {
  19. GenIdCount = genIdCount;
  20. IdGen = idGen;
  21. WorkerId = workerId;
  22. }
  23. //public void GenId()
  24. //{
  25. // Thread t = new Thread(new ThreadStart(Gen1Start));
  26. // t.Start();
  27. //}
  28. public void GenStart()
  29. {
  30. DateTime start = DateTime.Now;
  31. for (int i = 0; i < GenIdCount; i++)
  32. {
  33. var id = IdGen.NewLong();
  34. //ids.Add(id, i);
  35. //idList.Add(id);
  36. }
  37. DateTime end = DateTime.Now;
  38. Console.WriteLine($"++++++++++++++++++++++++++++++++++++++++WorkerId: {WorkerId}, total: {(end - start).TotalSeconds} s");
  39. Interlocked.Increment(ref Program.Count);
  40. }
  41. }
  42. }

雪花算法中非常好用的数字ID生成器