problem with hash map
posted 15 years ago
-
-
Number of slices to send:Optional 'thank-you' note:
-
-
In my jsp page I am having a Hash Map collection, when multiple request made to the jsp page the operation of Hash map is unpredictable. but when i replaced the Hash Map with string array every thing is working fine(execution in a synchronized manner). may i know the reason why execution of hash map during multiple request is unpredictable? is there any possibility of synchronizing the hash map
posted 15 years ago
-
-
Number of slices to send:Optional 'thank-you' note:
-
-
I don't understand what you're asking.
First of all, you don't "execute a HashMap." You access one.
Are you talking about actual synchronization, or the order in which entries are retrieved? Arrays aren't synchronized either, so... so far what you're saying isn't making any sense.
First of all, you don't "execute a HashMap." You access one.
Are you talking about actual synchronization, or the order in which entries are retrieved? Arrays aren't synchronized either, so... so far what you're saying isn't making any sense.
posted 15 years ago
-
-
Number of slices to send:Optional 'thank-you' note:
-
-
What are you doing with this hashmap from your requests?
Are you adding to it, removing from it, reading values from it, all three?
Where is this hashmap created?
Is it bound to a particular scope object?
Did you declare it right in the JSP?
If so, was it created outside of the service area (within <%! %> tags?).
Tell us a little more about what you are doing, what you are expecting, and what you're seeing and we can probably point out what is going wrong.
Are you adding to it, removing from it, reading values from it, all three?
Where is this hashmap created?
Is it bound to a particular scope object?
Did you declare it right in the JSP?
If so, was it created outside of the service area (within <%! %> tags?).
Tell us a little more about what you are doing, what you are expecting, and what you're seeing and we can probably point out what is going wrong.
Lalchand omprakash
Greenhorn
Posts: 12
posted 15 years ago
-
-
Number of slices to send:Optional 'thank-you' note:
-
-
yeah i have used the Hash map for the purpose of reading,writing the data. i have placed the hash map in "<% %>" scriplet along with code that will iterate over the collection. i think due to multiple request to the jsp page data race occurring in the jsp. i have tried synchronization is there any other way to avoid the data race problem.
posted 15 years ago
-
-
Number of slices to send:Optional 'thank-you' note:
-
-
My guess, you are looping through the HashMap, using its key set, correct? And then you are expecting it to maintain the order, in which those key/values were put. Isn't it?
If yes, then you need to read the docs of java.util.HashMap.
If yes, then you need to read the docs of java.util.HashMap.
posted 15 years ago
I'm not sure why you didn't answer my original question, or the questions asked by Ben.
What is happening? What do you *expect* to happen? Under what circumstances do you see the problem?
Please, *please* answer those questions--otherwise we're just guessing.
-
-
Number of slices to send:Optional 'thank-you' note:
-
-
Lalchand omprakash wrote:yeah i have used the Hash map for the purpose of reading,writing the data. i have placed the hash map in "<% %>" scriplet along with code that will iterate over the collection. i think due to multiple request to the jsp page data race occurring in the jsp. i have tried synchronization is there any other way to avoid the data race problem.
I'm not sure why you didn't answer my original question, or the questions asked by Ben.
What is happening? What do you *expect* to happen? Under what circumstances do you see the problem?
Please, *please* answer those questions--otherwise we're just guessing.
posted 15 years ago
If you have declared the map inside a set of <% ... %> tags then a new map will be created for each request and there will be no race condition between multiple requests.
"Placed" doesn't tell me whether this is the case or not.
As David mentioned, you really need to answer the questions asked of you fully.
Until you do that, nobody is going to be able to give you any meaningful help here.
-
-
Number of slices to send:Optional 'thank-you' note:
-
-
Lalchand omprakash wrote: i have placed the hash map in "<% %>" scriplet along with code that will iterate over the collection.
If you have declared the map inside a set of <% ... %> tags then a new map will be created for each request and there will be no race condition between multiple requests.
"Placed" doesn't tell me whether this is the case or not.
As David mentioned, you really need to answer the questions asked of you fully.
Until you do that, nobody is going to be able to give you any meaningful help here.
| You get good luck from rubbing the belly of a tiny ad: The new gardening playing cards kickstarter is now live! https://www.kickstarter.com/projects/paulwheaton/garden-cards |











