This week's book giveaway is in the Agile and other Processes forum.
We're giving away four copies of The Mikado Method and have Ola Ellnestam and Daniel Brolund 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
Register / Login


Win a copy of The Mikado Method this week in the Agile and other Processes forum!
JavaRanch » Java Forums » Java » Java in General
Reply 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: 104
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: 16692
    
  19

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

Joined: Aug 22, 2010
Posts: 2331
    
    2

Google has many sample codes. Try java threadlocal examples.
 
I agree. Here's the link: http://ej-technologies/jprofiler - if it wasn't for jprofiler, we would need to run our stuff on 16 servers instead of 3.
 
subject: ThreadLocal use to store Key and Value (like hash map)
 
Similar Threads
Some ThreadLocal issues
Using ThreadLocal with static methods
session.invalidate()
ThreadLocal and DB connection...
What is ThreadLocal?