• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

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

 
Shankar sanjay
Ranch Hand
Posts: 117
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Marshal
Pie
Posts: 21021
78
C++ Chrome Eclipse IDE Firefox Browser Java jQuery Linux VI Editor Windows
  • Likes 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
 
Shankar sanjay
Ranch Hand
Posts: 117
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
thanks Henry. Do you have any sample code?
 
Martin Vajsar
Sheriff
Posts: 3752
62
Chrome Netbeans IDE Oracle
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Google has many sample codes. Try java threadlocal examples.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic