模拟测试代码:
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
|
private static string _example = Guid.NewGuid().ToString(); private static UniqueCheck _uck = null ; static void Main(string[] args) { _uck = UniqueCheck.GetInstance(); _uck.Start(); _uck.SetIsShowMsg( false ); _uck.SetCacheMaxNum( 20000000 ); _uck.SetBlockNumExt( 1000000 ); _uck.SetTimeSpan( 6000 ); _uck.AddItem(_example); Thread[] threads = new Thread[ 20 ]; for ( int i = 0 ; i < 20 ; i++) { threads[i] = new Thread(AddInfo); threads[i].Start(); } Thread checkthread = new Thread(CheckInfo); checkthread.Start(); string value = Console.ReadLine(); checkthread.Abort(); for ( int i = 0 ; i < 50 ; i++) { threads[i].Abort(); } _uck.Stop(); } static void AddInfo() { while ( true ) { _uck.AddItem(Guid.NewGuid().ToString()); } } static void CheckInfo() { while ( true ) { Console.WriteLine( "开始时间:{0}..." , DateTime.Now.ToString( "yyyy-MM-dd HH:mm:ss.ffff" )); Console.WriteLine( "插入结果:{0}" , _uck.AddItem(_example)); Console.WriteLine( "结束时间:{0}" , DateTime.Now.ToString( "yyyy-MM-dd HH:mm:ss.ffff" )); //调整进程休眠时间,可以测试高并发的情况 //Thread.Sleep(1000); } } |
测试截图: