• Post Reply Bookmark Topic Watch Topic
  • New Topic

Hashtable for In-Memory Databse  RSS feed

 
Pearlo Muthukumaran
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
 
Michael Morris
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
 
Peter den Haan
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
 
Nick Faiz
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.
 
John Smith
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.
 
Jim Yingst
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.
 
Consider Paul's rocket mass heater.
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!