目录

void remove()

描述 (Description)

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

声明 (Declaration)

以下是java.lang.ThreadLocal.remove()方法的声明

public void remove()

参数 (Parameters)

NA

返回值 (Return Value)

此方法不返回任何值。

异常 (Exception)

NA

例子 (Example)

以下示例显示了java.lang.ThreadLocal.remove()方法的用法。

package com.iowiki;
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
↑回到顶部↑
WIKI教程 @2018