Skip to content

Commit

Permalink
自建线程池只用于频繁调用的重型逻辑,以及启动时可能产生争夺的场景
Browse files Browse the repository at this point in the history
  • Loading branch information
nnhy committed Jun 26, 2018
1 parent 72c4b90 commit 1ec2a91
Show file tree
Hide file tree
Showing 5 changed files with 6 additions and 10 deletions.
2 changes: 1 addition & 1 deletion NewLife.Core/Json/JsonConfig.cs
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ public static TConfig Current
XTrace.WriteLine("{0}的配置文件{1}有更新,重新加载配置!", typeof(TConfig), config.ConfigFile);

// 异步更新
ThreadPoolX.QueueUserWorkItem(() => config.Load(dcf));
ThreadPool.QueueUserWorkItem(s => config.Load(dcf));

return config;
}
Expand Down
2 changes: 1 addition & 1 deletion NewLife.Core/Net/SessionBase.cs
Original file line number Diff line number Diff line change
Expand Up @@ -323,7 +323,7 @@ Boolean ReceiveAsync(SocketAsyncEventArgs se, Boolean io)
if (io)
ProcessReceive(se);
else
ThreadPoolX.QueueUserWorkItem(() => ProcessReceive(se));
ThreadPoolX.QueueUserWorkItem(ProcessReceive, se);
}

return true;
Expand Down
6 changes: 1 addition & 5 deletions NewLife.Core/Xml/XmlConfig.cs
Original file line number Diff line number Diff line change
Expand Up @@ -3,13 +3,9 @@
using System.Reflection;
using System.Text;
using System.Threading;
using System.Threading.Tasks;
using System.Xml.Serialization;
using NewLife.Log;
using NewLife.Threading;
#if NET4
using Task = System.Threading.Tasks.TaskEx;
#endif

namespace NewLife.Xml
{
Expand Down Expand Up @@ -50,7 +46,7 @@ public static TConfig Current
XTrace.WriteLine("{0}的配置文件{1}有更新,重新加载配置!", typeof(TConfig), config.ConfigFile);

// 异步更新
ThreadPoolX.QueueUserWorkItem(() => config.Load(dcf));
ThreadPool.QueueUserWorkItem(s => config.Load(dcf));

return config;
}
Expand Down
2 changes: 1 addition & 1 deletion XCode/Cache/EntityCache.cs
Original file line number Diff line number Diff line change
Expand Up @@ -145,7 +145,7 @@ void UpdateCacheAsync(String reason)
// 控制只有一个线程能更新
if (Interlocked.CompareExchange(ref _updating, 1, 0) != 0) return;

ThreadPoolX.QueueUserWorkItem(() => UpdateCache(reason));
ThreadPoolX.QueueUserWorkItem(UpdateCache, reason);
}

void UpdateCache(String reason)
Expand Down
4 changes: 2 additions & 2 deletions XCode/Entity/IEntityModule.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
using System.Collections;
using System.Collections.Concurrent;
using System.Collections.Generic;
using NewLife.Threading;
using System.Threading;

namespace XCode
{
Expand Down Expand Up @@ -59,7 +59,7 @@ public class EntityModules : IEnumerable<IEntityModule>
public virtual void Add(IEntityModule module)
{
// 异步添加实体模块,避免死锁。实体类一般在静态构造函数里面添加模块,如果这里同步初始化会非常危险
ThreadPoolX.QueueUserWorkItem(AddAsync, module);
ThreadPool.QueueUserWorkItem(s => AddAsync(module));
}

/// <summary>添加实体模块</summary>
Expand Down

0 comments on commit 1ec2a91

Please sign in to comment.