| 网站首页 | 业界新闻 | 小组 | 威客 | 人才 | 下载频道 | 博客 | 代码贴 | 在线编程 | 编程论坛
欢迎加入我们,一同切磋技术
用户名:   
 
密 码:  
共有 588 人关注过本帖
标题:JAVA的Thread局部变量ThreadLocal
只看楼主 加入收藏
shitainong
Rank: 1
等 级:新手上路
帖 子:70
专家分:0
注 册:2012-7-6
结帖率:0
收藏
 问题点数:0 回复次数:0 
JAVA的Thread局部变量ThreadLocal
ThreadLocal: Thread局部变量-------ThreadLocalVariable


java.lang
Class ThreadLocal<T>
java.lang.Object
java.lang.ThreadLocal<T>
Direct Known Subclasses:
InheritableThreadLocal
public class ThreadLocal<T>
extends Object
This class provides thread-local variables. These variables differ from their normal counterparts in that each thread that accesses one (via its get or set method) has its own, independently initialized copy of the variable. ThreadLocal instances are typically private static fields in classes that wish to associate state with a thread


ThreadLocal为每个线程使用该变量的线程提供一个独立的副本,这样每个副本读可以独立改变自己的副本,不受其他线程的影响




这个类有四个方法:

Method Summary

Tget()
Returns the value in the current thread's copy of this thread-local variable.

//返回当前线程对应的局部变量的值
protected T initialValue()
Returns the current thread's initial value for this thread-local variable.

//返回该线程变量的初始值,缺省值返回null,protected修饰,便于子类覆盖,是一个延迟调用,当第一次调用set(),get()时才执行1次
void remove()
Removes the value for this ThreadLocal.

//删除当前局部变量的值
void set(T value)
Sets the current thread's copy of this thread-local variable to the specified value.

//设置当前线程局部变量的值:www.

搜索更多相关主题的帖子: its static provides private method 
2013-03-13 16:13
快速回复:JAVA的Thread局部变量ThreadLocal
数据加载中...
 
   



关于我们 | 广告合作 | 编程中国 | 清除Cookies | TOP | 手机版

编程中国 版权所有,并保留所有权利。
Powered by Discuz, Processed in 0.017224 second(s), 7 queries.
Copyright©2004-2024, BCCN.NET, All Rights Reserved