| Author |
HashMap
|
Mary Taylor
Ranch Hand
Joined: Sep 11, 2000
Posts: 319
|
|
I am attempting to store values in a HashMap. It's not happening, and I haven't determined why. private HashMap cache = new Hashmap(); In a method later on, I code: cache.put(cacheKey.toUpperCase(), pageToStore); I am using the debugger. Valid values are in both the key and the value. What should be my thought process at this time? Thanks.
|
 |
Ron Newman
Ranch Hand
Joined: Jun 06, 2002
Posts: 1056
|
|
|
Could you show us a small, but complete, program that demonstrates the problem?
|
Ron Newman - SCJP 1.2 (100%, 7 August 2002)
|
 |
Mary Taylor
Ranch Hand
Joined: Sep 11, 2000
Posts: 319
|
|
|
It will take a while to get a short complete program demonstrating this, but I'll give it a shot. There is so much going on here in this one; that is why I didn't send code to begin with.
|
 |
Marilyn de Queiroz
Sheriff
Joined: Jul 22, 2000
Posts: 9033
|
|
|
How do you know that they're not there?
|
JavaBeginnersFaq
"Yesterday is history, tomorrow is a mystery, and today is a gift; that's why they call it the present." Eleanor Roosevelt
|
 |
Mary Taylor
Ranch Hand
Joined: Sep 11, 2000
Posts: 319
|
|
|
Used isEmpty() test to determine HashMap was empty. I think I may be expiring the entry in the cache with a Thread I'm using to do that. Just didn't think it was happening immediately. I'm debugging. Will get back to you if I'm not successful.
|
 |
Ilja Preuss
author
Sheriff
Joined: Jul 11, 2001
Posts: 14112
|
|
Originally posted by Betty Schwartz: Used isEmpty() test to determine HashMap was empty. I think I may be expiring the entry in the cache with a Thread I'm using to do that. Just didn't think it was happening immediately. I'm debugging. Will get back to you if I'm not successful.
Notice that HashMap is not threadsafe, so you need to synchronize yourself or get a synchronized wrapper from the Collections class to safely access it from different threads.
|
The soul is dyed the color of its thoughts. Think only on those things that are in line with your principles and can bear the light of day. The content of your character is your choice. Day by day, what you do is who you become. Your integrity is your destiny - it is the light that guides your way. - Heraclitus
|
 |
Mary Taylor
Ranch Hand
Joined: Sep 11, 2000
Posts: 319
|
|
Can you explain more how to get a synchronized wrapper or otherwise make this operation threadsafe? This is my first time to need to do that. I am not familiar with synchronized wrappers. Thank you.
|
 |
Jim Yingst
Wanderer
Sheriff
Joined: Jan 30, 2000
Posts: 18670
|
|
|
See the API for Collections.synchronizedMap(Map).
|
"I'm not back." - Bill Harding, Twister
|
 |
 |
|
|
subject: HashMap
|
|
|