The java.lang.ThreadLocal class provides thread-local variables.
Following is the declaration for java.lang.ThreadLocal class −
public class ThreadLocal<T> extends Object
Sr.No. | Constructor & Description |
---|---|
1 | ThreadLocal() This creates a thread local variable. |
Sr.No. | 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. |
This class inherits methods from the following classes −