Java ThreadLocal remove()方法

java.lang.ThreadLocal.remove() 方法删除该线程当前线程局部变量的值。

1 语法

public void remove()

2 参数

filename : 这是加载文件。

3 返回值

此方法不返回任何值。

4 示例 

package com.yiidian;

/**
 * 一点教程网: http://www.yiidian.com
 */
/**
 * Java ThreadLocal remove()方法
 */
import java.lang.*;

public class ThreadLocalDemo {

   public static void main(String[] args) {

     ThreadLocal<Integer> tlocal = new ThreadLocal<Integer>();  

     /* sets the current thread's copy of this thread-local variable
     to the specified value. */

     tlocal.set(50);
     // returns the current thread's value of this thread-local
     System.out.println("value = " + tlocal.get());
 
     // removes the current thread's value 
     tlocal.remove();
     // returns the current thread's value of this thread-local
     System.out.println("value = " + tlocal.get());
   }
}

输出结果为:

value = 50
value = null

 

热门文章

优秀文章