-
Notifications
You must be signed in to change notification settings - Fork 38
/
Demo.cs
40 lines (31 loc) · 874 Bytes
/
Demo.cs
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
using System;
using System.Collections.Generic;
using System.IO;
using System.Text;
using System.Threading;
class SafeObjectPoolDemo
{
public void test()
{
var pool = new SafeObjectPool.ObjectPool<MemoryStream>(10, () => new MemoryStream(), obj =>
{
if (DateTime.Now.Subtract(obj.LastGetTime).TotalSeconds > 3)
{
var dt = Encoding.UTF8.GetBytes("我是中国人");
obj.Value.Write(dt, 0, dt.Length);
}
});
for (var a = 0; a < 100; a++)
{
new Thread(() =>
{
for (var b = 0; b < 1000; b++)
{
var item = pool.Get();
pool.Return(item);
}
Console.WriteLine(pool.StatisticsFullily);
}).Start();
}
}
}