Java.lang.ThreadLocal Class

Java.lang.ThreadLocal Class


The java.lang.ThreadLocal class provides thread-local variables.

Class declaration

Following is the declaration for java.lang.ThreadLocal class:

public class ThreadLocal<T>
   extends Object

Class constructors

S.N. Constructor & Description
1 ThreadLocal()This creates a thread local variable.

Class methods

S.N. Method & Description
1 T get()

This method returns the value in the current thread’s copy of this thread-local variable.

2 protected T initialValue()

This method returns the current thread’s “initial value” for this thread-local variable.

3 void remove()

This method removes the current thread’s value for this thread-local variable.

4 void set(T value)

This method sets the current thread’s copy of this thread-local variable to the specified value.

Methods inherited

This class inherits methods from the following classes:

  • java.lang.Object

Was this article helpful?

Related Articles

Leave A Comment?

You must be logged in to post a comment.