threadlocal
- 网络线程
-
Needless to say , the performance of ThreadLocal was quite poor .
不用说,ThreadLocal的性能是相当差的。
-
Using ThreadLocal makes sense when you need to store variable instances on a per-thread basis .
当您需要以线程为单位存储变量实例时,使用ThreadLocal很有意义。
-
With these new improvements , ThreadLocal should be faster than other techniques such as pooling .
有了这些提高,ThreadLocal应该比其它技术,如用池,更快。
-
By using ThreadLocal , we can reduce contention by giving each thread its own copy of certain critical objects .
通过使用ThreadLocal,给予每个线程它自己的特定临界对象的副本,我们就可以减少争用。
-
To create a thread-local variable , you instantiate an object of class ThreadLocal .
要创建一个线程局部变量,请实例化类ThreadLocal的一个对象。
-
Using ThreadLocal to simplify debug logging
用ThreadLocal简化调试日志纪录
-
In this way , we can think of a ThreadLocal as allowing us to create a per-thread-singleton .
这样,我们可以认为ThreadLocal允许我们创建每线程单子。
-
You can use ThreadLocal variables to store any sort of per-request context information using the per-thread-singleton technique described earlier .
您可以通过前面讲述的每线程单子技术用ThreadLocal变量来存储各种每请求(per-request)上下文信息。
-
However , the ThreadLocal class makes it much easier for us to manage the process of associating a thread with its per-thread data .
而ThreadLocal则使我们能更容易地把线程和它的每线程(per-thread)数据成功地联系起来。
-
One way of getting around this problem is to create a custom SubjectHolder class that wraps a static ThreadLocal to store the current Subject .
一种解决这个问题的方法是创建一个自定义SubjectHolder类,它包装了一个staticThreadLocal以存储当前Subject。
-
Other applications for ThreadLocal in which pooling would not be a useful alternative include storing or accumulating per-thread context information for later retrieval .
其它适合使用ThreadLocal但用池却不能成为很好的替代技术的应用程序包括存储或累积每线程上下文信息以备稍后检索之用这样的应用程序。
-
In the last installment in this series , we 'll examine ThreadLocal , an oft-neglected facility of the Thread API .
在本系列的最后一部分,我们将讨论ThreadLocal,它是ThreadAPI中经常被忽视的一个工具。
-
Thus if we only had the ThreadLocal cache of the database connection handles , we would not be able to initiate a close of all open handles .
因此,如果我们只有数据库连接句柄的ThreadLocal缓存,我们将不能发起对所有开放句柄的关闭操作。
-
The next-fastest data structure is HashMap , followed by ThreadLocal ( essentially , a specialized hash table in which the current thread is the key ) .
更慢一点儿的数据结构是HashMap,然后是ThreadLocal(这基本上是一个以当前线程作为键的特殊散列表)。
-
The reason for this poor performance is that the Thread . currentThread () method is quite expensive , accounting for more than two-thirds of the ThreadLocal . get ()
性能这么差的原因是Thread.currentThread()方法的花费非常大,占了ThreadLocal.get()运行时间的三分之二还多。
-
Java compilers offer no special language support for thread-local variables ; instead , they are implemented with the ThreadLocal class , which has special support in the core Thread class .
Java编译器对线程局部变量不提供特别的语言支持;相反地,它用ThreadLocal类实现这些支持,核心Thread类中有这个类的特别支持。
-
ThreadLocal variables are different from normal variables in that each thread has its own individually initialized instance of the variable , which it accesses via get () or set () methods .
ThreadLocal变量与常规变量的不同之处在于,每个线程都有其各自初始化的变量实例,这通过get()或set()方法予以评估。
-
It isn 't a particularly good implementation ( although it is quite similar to the initial implementation ), as it would likely perform poorly , but it illustrates clearly how ThreadLocal behaves .
它不是一个特别好的实现(虽然它与最初实现非常相似),所以很可能性能不佳,但它清楚地说明了ThreadLocal的工作方式。
-
Using ThreadLocal allows us to bypass the complexity of determining when to synchronize in order to achieve thread-safety , and it improves scalability because it doesn 't require any synchronization .
使用ThreadLocal使我们可以绕过为实现线程安全而对何时需要同步进行判断的复杂过程,而且因为它不需要任何同步,所以也改善了可伸缩性。
-
Instead , the Thread class was modified to support ThreadLocal by adding an instance variable to Thread that holds a HashMap mapping thread-local variables to their values for the current thread .
相反地,人们通过给Thread添加一个实例变量(该变量用于保存当前线程的从线程局部变量到它的值的映射的HashMap)来修改Thread类以支持ThreadLocal。
-
In a multi-thread application , user-defined threads are not initiated by a servlet thread , thus they do not have FacesContext initialized as a ThreadLocal variable .
在多线程程序中,用户定义的线程并不是由服务线程初始化的,因此它们并没有将FacesContext初始化为一个ThreadLocal变量。
-
Based on the deficiency , this paper analyses Java Memory Model ( JMM ), the reason for DCL invalidation and the interior mechanism of " ThreadLocal " . The strategy to design the object of class by singleton model is proposed .
针对这些不足,本文结合实例分析了Java内存模型(JMM)、DCL失效原因以及ThreadLocal的内部运行机制,给出了将类的对象设计成Singleton模式的策略。