Win a copy of Murach's Python Programming this week in the Jython/Python forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic

problem with hash map  RSS feed

 
Lalchand omprakash
Greenhorn
Posts: 12
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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

 
David Newton
Author
Rancher
Posts: 12617
IntelliJ IDE Ruby
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
 
Ben Souther
Sheriff
Posts: 13411
Firefox Browser Redhat VI Editor
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
 
Lalchand omprakash
Greenhorn
Posts: 12
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
 
Adeel Ansari
Ranch Hand
Posts: 2874
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
 
David Newton
Author
Rancher
Posts: 12617
IntelliJ IDE Ruby
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
 
Ben Souther
Sheriff
Posts: 13411
Firefox Browser Redhat VI Editor
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!