Log4net LogicalThreadContext和ThreadContext [英] Log4net LogicalThreadContext and ThreadContext

查看:137
本文介绍了Log4net LogicalThreadContext和ThreadContext的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

嗨..朋友们

LogicalThreadContext和ThreadContext之间有什么区别,哪一个很好.
以及如何使用它们.
我已经尝试了Google搜索,但不了解.
请引导我.

谢谢

Hi..Friends

What is the diffrance between LogicalThreadContext and ThreadContext,which one is good.
and how to use them.
I have tried the googling but do not understand.
Please guid me.

Thanks

推荐答案

此语句提供的清晰度如何:
ThreadContext将数据存储在线程本地插槽中.这被附加到特定的运行时线程.在v1.0和v1.1中,此线程对应于OS线程. ThreadContext数据仅限于一个线程,其他线程不可见.

LogicalThreadContext将其数据存储在CallContext插槽中. CallContext数据本质上是存储在逻辑线程本地的数据.逻辑线程可以从一个运行时线程跳到另一个运行时线程.除此之外,该行为与ThreadContext相同.


实际上,由于我们不允许LogicalThreadContext数据跨越远程边界(我们未实现ILogicalThreadAffinative接口),因此LogicalThreadContext的行为几乎与ThreadContext相同.据我所知,LogicalThreadContext将数据传输到另一个线程的唯一地方是异步委托调用,该异步委托调用可能在另一个线程上执行(但不是在ThreadPool.QueueUserWorkItem上执行).


参考: Nicko Cadell的回答类似的问题 [ ^ ]
What about clarity provided by this statement:
The ThreadContext stores data in a thread local slot. This is attached to a specific runtime thread. In v1.0 and v1.1 this thread corresponds to an OS thread. The ThreadContext data is limited to that one thread and not visible from other threads.

The LogicalThreadContext stores its data in a CallContext slot. The CallContext data is essentially data stored local to the logical thread. The logical thread can jump from one runtime thread to another. Other than that the behaviour will be the same as for the ThreadContext.


In practice the LogicalThreadContext will behave nearly identically to the ThreadContext because we do not allow our LogicalThreadContext data to cross a remoting boundary (we do not implement the ILogicalThreadAffinative interface). As far as I know the only places where the LogicalThreadContext will transfer the data to another thread is for asynchronous delegate invocations which might execute on a different thread (but not ThreadPool.QueueUserWorkItem).


Reference: Nicko Cadell''s reply to similar asked question[^]


这篇关于Log4net LogicalThreadContext和ThreadContext的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆