aspose file tools
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


Win a copy of The Software Craftsman this week in the Agile forum!
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: 19528
    
  42

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: 3680
    
  61

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