Win a copy of The Journey To Enterprise Agility this week in the Agile and Other Processes forum! And see the welcome thread for 20% off.
  • 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:
  • Jeanne Boyarsky
  • Liutauras Vilda
  • Campbell Ritchie
  • Tim Cooke
  • Bear Bibeault
Sheriffs:
  • Paul Clapham
  • Junilu Lacar
  • Knute Snortum
Saloon Keepers:
  • Ron McLeod
  • Ganesh Patekar
  • Tim Moores
  • Pete Letkeman
  • Stephan van Hulst
Bartenders:
  • Carey Brown
  • Tim Holloway
  • Joe Ess

Hashtable for In-Memory Databse  RSS feed

 
Ranch Hand
Posts: 79
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi,
I need some design inputs for caching
150 KB sized objects in the main memory for
performance requirements.
I am planning to use a hastable where I shall store a byte array chunk of above size with some name assigned to it and shall encapsulate it within a management object for getting , putting etc., the expected size is 60 objects at any point of time.
Please let me know whether above will serve the
purpose of my intention to build a quick
"MAIN-MEMORY" Database?
Thanks in advance
Muthu
 
Ranch Hand
Posts: 3451
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Greetings Muthu,
Welcome to JavaRanch, the absolute best site on the www for Java information. We don't have many rules around here, but we do have one. Please change your display name to a first and last name to conform with the JavaRanch Naming Policy.
You can change it here: Change your display name.
Michael Morris
 
Pearlo Muthukumaran
Ranch Hand
Posts: 79
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Can anyone please respond..........to the query ??
:-(
Rgds
Muthu
 
author
Ranch Hand
Posts: 3252
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Well, it will do something, and work. Will it do what you want? Well, what do you want? A database? I associate a database with querying facilities, persistence, and so forth -- it won't do that. Or do you want a cache, perhaps? Then you'd need to talk about a cache strategy unless you're happy not to cap your memory footprint. For a simple LRU cache, use LinkedHashMap. In other cases, use HashMap. Avoid Hashtable.
- Peter
 
Greenhorn
Posts: 11
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Also, consider making it static, as it's likely that the information within it will serve for all objects that will want to call on it.
Things may become more difficult if you have many objects wishing to alter the data it holds at once - you can always synchronize but performance might be an issue.
If you simply want to cache something HashMap is a good bet, as the previous post pointed out.
 
Ranch Hand
Posts: 2937
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Also, pay close attention to the potential for memory leaks (caches are a common source), -- when you cache your objects by adding them to a collection, they will not be garbage collected until you clear the cache.
Eugene.
 
Wanderer
Sheriff
Posts: 18671
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
...unless of course you use a WeakHashMap for the caching. This will allow garbage collection of any objects whose only reference is in the WeakHashMap.
 
Pearlo Muthukumaran
Ranch Hand
Posts: 79
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi all,
Thanks for the responses..
I am planning to use a WeakHashmap for the same. I have also gone through some fundas of the same.
seems promising.
Btw, the cache will be characterized by higher number of read-operations (ie external components reading from the cache), in case of a static class implementation, is synchronization important.
The data chunks in hashmap will be only read and deleted never updated..
Any lights please ?
Rgds
Muthu
 
John Smith
Ranch Hand
Posts: 2937
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I am planning to use a WeakHashmap for the same. I have also gone through some fundas of the same. seems promising.
You mentioned earlier that you were planning to use a name for the key. If so, be very careful, -- if the keys in your WeakHashMap are string literals, your weak map entries may never be elligble for garbage collection
Btw, the cache will be characterized by higher number of read-operations (ie external components reading from the cache), in case of a static class implementation, is synchronization important. The data chunks in hashmap will be only read and deleted never updated.
If your cache is read-only (immutable), then no synchronization is needed. However, if you populate it as you go along, then you should synchronize the access to it.
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!