This week's book giveaway is in the Mac OS forum.
We're giving away four copies of a choice of "Take Control of Upgrading to Yosemite" or "Take Control of Automating Your Mac" and have Joe Kissell on-line!
See this thread for details.
The moose likes Java in General and the fly likes ThreadLocal use to store Key and Value (like hash map) Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


JavaRanch » Java Forums » Java » Java in General
Bookmark "ThreadLocal use to store Key and Value (like hash map)" Watch "ThreadLocal use to store Key and Value (like hash map)" New topic
Author

ThreadLocal use to store Key and Value (like hash map)

Shankar sanjay
Ranch Hand

Joined: Sep 14, 2009
Posts: 117
Hi,

I have a requirement in my project to store and get values throughout the transaction (like hashmap, key and value). As far as i know, we can store only one object (like list) in ThreadLocal.

Is there any want to store key and value in ThreadLocal.

please help me.

Henry Wong
author
Sheriff

Joined: Sep 28, 2004
Posts: 18876
    
  40

Shankar sanjay wrote:
I have a requirement in my project to store and get values throughout the transaction (like hashmap, key and value). As far as i know, we can store only one object (like list) in ThreadLocal.

Is there any want to store key and value in ThreadLocal.



One option.... store a Map object in the ThreadLocal.

Henry


Books: Java Threads, 3rd Edition, Jini in a Nutshell, and Java Gems (contributor)
Shankar sanjay
Ranch Hand

Joined: Sep 14, 2009
Posts: 117
thanks Henry. Do you have any sample code?
Martin Vajsar
Sheriff

Joined: Aug 22, 2010
Posts: 3610
    
  60

Google has many sample codes. Try java threadlocal examples.
 
GeeCON Prague 2014
 
subject: ThreadLocal use to store Key and Value (like hash map)