Skip to content

Commit ab2de18

Browse files
committed
v3.0.0
1 parent a6d78e3 commit ab2de18

File tree

7 files changed

+147
-131
lines changed

7 files changed

+147
-131
lines changed

SafeObjectPool.csproj

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
<AssemblyName>SafeObjectPool</AssemblyName>
66
<PackageId>SafeObjectPool</PackageId>
77
<RootNamespace>SafeObjectPool</RootNamespace>
8-
<Version>2.3.1</Version>
8+
<Version>3.0.0</Version>
99
<GeneratePackageOnBuild>true</GeneratePackageOnBuild>
1010
<PackageProjectUrl>https://github.com/2881099/SafeObjectPool</PackageProjectUrl>
1111
<Description>应用场景:连接池,资源池等等</Description>

SafeObjectPool.xml

Lines changed: 8 additions & 2 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

SafeObjectPool/DefaultPolicy.cs

Lines changed: 1 addition & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,4 @@
11
using System;
2-
using System.Collections.Generic;
3-
using System.Text;
42
using System.Threading.Tasks;
53

64
namespace SafeObjectPool
@@ -16,7 +14,7 @@ public class DefaultPolicy<T> : IPolicy<T>
1614
public int AsyncGetCapacity { get; set; } = 10000;
1715
public bool IsThrowGetTimeoutException { get; set; } = true;
1816
public bool IsAutoDisposeWithSystem { get; set; } = true;
19-
public int CheckAvailableInterval { get; set; } = 5;
17+
public int CheckAvailableInterval { get; set; } = 3;
2018

2119
public Func<T> CreateObject;
2220
public Action<Object<T>> OnGetObject;
@@ -33,15 +31,13 @@ public void OnDestroy(T obj)
3331

3432
public void OnGet(Object<T> obj)
3533
{
36-
//Console.WriteLine("Get: " + obj);
3734
OnGetObject?.Invoke(obj);
3835
}
3936

4037
#if net40
4138
#else
4239
public Task OnGetAsync(Object<T> obj)
4340
{
44-
//Console.WriteLine("GetAsync: " + obj);
4541
OnGetObject?.Invoke(obj);
4642
return Task.FromResult(true);
4743
}
@@ -54,7 +50,6 @@ public void OnGetTimeout()
5450

5551
public void OnReturn(Object<T> obj)
5652
{
57-
//Console.WriteLine("Return: " + obj);
5853
}
5954

6055
public bool OnCheckAvailable(Object<T> obj)

SafeObjectPool/IObjectPool.cs

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,4 @@
11
using System;
2-
using System.Collections.Generic;
3-
using System.Text;
42
using System.Threading.Tasks;
53

64
namespace SafeObjectPool
@@ -25,8 +23,9 @@ public interface IObjectPool<T> : IDisposable
2523
/// 将对象池设置为不可用,后续 Get/GetAsync 均会报错,同时启动后台定时检查服务恢复可用
2624
/// </summary>
2725
/// <param name="exception"></param>
26+
/// <param name="lastGetTime"></param>
2827
/// <returns>由【可用】变成【不可用】时返回true,否则返回false</returns>
29-
bool SetUnavailable(Exception exception);
28+
bool SetUnavailable(Exception exception, DateTime lastGetTime);
3029

3130
/// <summary>
3231
/// 统计对象池中的对象

SafeObjectPool/IPolicy.cs

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,4 @@
11
using System;
2-
using System.Collections.Generic;
3-
using System.Text;
42
using System.Threading.Tasks;
53

64
namespace SafeObjectPool

SafeObjectPool/Object.cs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,4 @@
11
using System;
2-
using System.Collections.Generic;
3-
using System.Text;
42
using System.Threading;
53

64
namespace SafeObjectPool
@@ -16,7 +14,8 @@ public static Object<T> InitWith(IObjectPool<T> pool, int id, T value)
1614
Id = id,
1715
Value = value,
1816
LastGetThreadId = Thread.CurrentThread.ManagedThreadId,
19-
LastGetTime = DateTime.Now
17+
LastGetTime = DateTime.Now,
18+
LastGetTimeCopy = DateTime.Now
2019
};
2120
}
2221

@@ -42,6 +41,7 @@ public static Object<T> InitWith(IObjectPool<T> pool, int id, T value)
4241

4342
/// 最后获取时的时间
4443
public DateTime LastGetTime { get; internal set; }
44+
public DateTime LastGetTimeCopy { get; internal set; }
4545

4646
/// <summary>
4747
/// 最后归还时的时间

0 commit comments

Comments
 (0)