ThreadLocal类

Java5之后,为ThreadLocal类增加了泛型支持,即ThreadLocal<T>

通过使用ThreadLocal类可以简化多线程编时的并发访问,使用这个工具类可以很简洁的隔离多线程程序的竞争资源。

实现方法:通过为每一个使用该变量的线程都提供一个变量值的副本。使得每一个线程都可以独立的改变自己的副本,而不会和其他线程的副本发生冲突。

有如下方法:

T get()
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.
void remove()
Removes the current thread's value for this thread-local variable.
void set(T value)
Sets the current thread's copy of this thread-local variable to the specified value.

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值