aspose file tools*
The moose likes Java in General and the fly likes HashMap performance and reliability Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Spring in Action this week in the Spring forum!
JavaRanch » Java Forums » Java » Java in General
Bookmark "HashMap performance and reliability" Watch "HashMap performance and reliability" New topic
Author

HashMap performance and reliability

Tim Shkembi
Greenhorn

Joined: Aug 07, 2012
Posts: 2

Since database not an option i need to know if the Java Hash Map would hold reliably a couple of million objects and what server configuration that would need?
William P O'Sullivan
Ranch Hand

Joined: Mar 28, 2012
Posts: 859

Greetings Tim..

That would all depend on the size (internally) of each object in your HashMap.

Performance in memory should be okay, again depending on your infrastructure.

For a million entries though, I would look at distribute caching across multiple nodes.
Especially if you're in a HA environment, and cannot afford the VM/app server to crash.

WP
Paul Clapham
Bartender

Joined: Oct 14, 2005
Posts: 18651
    
    8

Sure, provided you have enough memory then it will hold those objects reliably.

However I don't understand what you mean by "server configuration" in your question. As far as I can see from your stated requirements (store objects, not in a database) all you need to do is to provide enough memory.
Tim Shkembi
Greenhorn

Joined: Aug 07, 2012
Posts: 2
Appreciate your comments. It is running fine so far after we increased the memory on the server. That's what I meant by configuration on the server.
The Hashmap is created only once by reading a Flat file and it will be recreated in case no reference to it.
Just wonder if the Hashhmap will keep the 2 million Objects Intact in the long run ?
Forgot to tell you that Objects are of the same datatype and have 7 strings with only getters.
Paul Clapham
Bartender

Joined: Oct 14, 2005
Posts: 18651
    
    8

If you're asking if objects are going to disappear mysteriously from the HashMap with no action on your part, then no. Of course not.
Winston Gutkowski
Bartender

Joined: Mar 17, 2011
Posts: 8008
    
  22

Tim Shkembi wrote:Appreciate your comments. It is running fine so far after we increased the memory on the server. That's what I meant by configuration on the server.
The Hashmap is created only once by reading a Flat file and it will be recreated in case no reference to it.

Not quite sure what that last bit means, but whatever.

A few issues I can see with this approach:
1. Start-up time. Something, somewhere, has to read and load those 2 million objects; and anything that wants to use your internal HashMap will have to wait until it does.
2. Does your application update any of these values? If so, as the song goes: "There may be troubles ahead..." and you won't be dancing when you have to face the music.

Databases really are very easy these days. In fact, JavaDB (or whatever it's called now) content can be shipped right along with your jar. If it was 200 items I might say don't bother; but 2 million?

Winston

Isn't it funny how there's always time and money enough to do it WRONG?
Articles by Winston can be found here
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: HashMap performance and reliability