Win a copy of Real-World Software Development: A Project-Driven Guide to Fundamentals in Java this week in the Agile and Other Processes forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Paul Clapham
  • Liutauras Vilda
  • Knute Snortum
  • Bear Bibeault
Sheriffs:
  • Devaka Cooray
  • Jeanne Boyarsky
  • Junilu Lacar
Saloon Keepers:
  • Ron McLeod
  • Stephan van Hulst
  • Tim Moores
  • Carey Brown
  • salvin francis
Bartenders:
  • Tim Holloway
  • Piet Souris
  • Frits Walraven

problem with hash map

 
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

 
Author
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.
 
Sheriff
Posts: 13411
Firefox Browser VI Editor Redhat
  • 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.
 
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
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 VI Editor Redhat
  • 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.
 
You can't expect to wield supreme executive power just because
Java file APIs (DOC, XLS, PDF, and many more)
https://products.aspose.com/total/java
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!