ThreadLocal – per-thread singleton object

A thread-local variable effectively provides a separate copy of its value for each thread that uses it. Each thread can see only the value associated with that thread, and is unaware that other threads may be using or modifying their own copies.

For instance, its a handy utility to store Hibernate Session objects which are inherently NOT thread-safe.

For beginners (like me), suffice to say that ThreadLocal class provides a hashmap similar to < threadId, Object> so each thread can see only what it has stored and not what other threads have added. Its like a thread-specific dictionary exposing a neat interface.

Good article

Advertisements

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

%d bloggers like this: