java.lang.ThreadLocal.get()%uA0方法返回此线程局部变量的当前线程副本中的值。
声明
以下是java.lang.ThreadLocal.get()方法的声明
public T get()
参数
-
NA
返回值
此方法返回此线程局部变量的当前线程的值。
异常
-
NA
例子
下面的例子显示java.lang.ThreadLocal.get()方法的使用。
package com.yiibai import java.lang.* public class ThreadLocalDemo { public static void main(String[] args) { ThreadLocal<Integer> tlocal = new ThreadLocal<Integer>() tlocal.set(100) // returns the current thread&aposs value System.out.println("value = " + tlocal.get()) tlocal.set(90) // returns the current thread&aposs value of System.out.println("value = " + tlocal.get()) } }
让我们来编译和运行上面的程序,这将产生以下结果:
value = 100 value = 90