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
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: 115
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: 18120
    
  39

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: 115
thanks Henry. Do you have any sample code?
Martin Vajsar
Sheriff

Joined: Aug 22, 2010
Posts: 3438
    
  47

Google has many sample codes. Try java threadlocal examples.
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: ThreadLocal use to store Key and Value (like hash map)
 
Similar Threads
What is ThreadLocal?
session.invalidate()
Using ThreadLocal with static methods
Some ThreadLocal issues
ThreadLocal and DB connection...