Menu Bar

Drop Down MenusCSS Drop Down MenuPure CSS Dropdown Menu

Sunday, 4 December 2016

What is ThreadLocal variable in Java ?

Previously we have discussed about

Class ThreadLocal<T>

Direct Known Subclasses:
InheritableThreadLocal

Declaration of ThreadLocal:
public class ThreadLocal<T>
extends Object

ThreadLocal class provides thread-local variables. ThreadLocal instances are typically private static fields in classes that wish to associate state with a thread (e.g., a user ID ). 

These variables differ from their normal counterparts in that each thread that accesses one  (via its get or set method) has its own, independently initialized copy of the variable.

Each thread holds an implicit reference to its copy of a thread-local variable as long as the thread is alive and the ThreadLocal instance is accessible; after a thread goes away, all of its copies of thread-local instances are subject to garbage collection (unless other references to these copies exist).

Constructor Summary of ThreadLocal:

Constructor
Description
ThreadLocal()
Creates a thread local variable.

Method Summary of ThreadLocal:

Modifier and Method Name
Description
T get()
Returns the value in the current thread's copy of this thread-local variable.
protected T initialValue()
Returns the current thread's "initial value" for this thread-local variable.
void remove()
Removes the current thread's value for this thread-local variable.
void set(T value)
Sets the current thread's copy of this thread-local variable to the specified value.
      


Blog Author - Pushkar Khosla,
Software Developer by Profession with 3.0 Yrs of Experience , through this blog i'am sharing my industrial Java Knowledge to entire world. For any question or query any one can comment below or mail me at pushkar.itsitm52@gmail.com.

This blog is all about to learn Core Java ,Interview Programs and Coding tricks to polish your Java Knowledge. If you like the content of this blog please share this with your friends.



Share this Blog with yours Friends !!

No comments:

Post a Comment