This week's book giveaway is in the Servlets forum.
We're giving away four copies of Murach's Java Servlets and JSP and have Joel Murach on-line!
See this thread for details.
The moose likes Java in General and the fly likes Which one would be Optimal? ( Map Vs Data Base) Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Murach's Java Servlets and JSP this week in the Servlets forum!
JavaRanch » Java Forums » Java » Java in General
Bookmark "Which one would be Optimal? ( Map Vs Data Base)" Watch "Which one would be Optimal? ( Map Vs Data Base)" New topic
Author

Which one would be Optimal? ( Map Vs Data Base)

Ramaswamy Srinivasan
Ranch Hand

Joined: Aug 31, 2004
Posts: 295
Dear All,

Back, into this forum, after quite a long time.

Now, I have a scenario, where some information is stored in Database.

I fetch the information, and store the data in a Map. Later at some point of time, I need information, which would be a sub-set of what is in the Map.

Now, would it be wise, to use the Map to hit the Database and get them?

What would be the several constraints that would be considered here?

Thanks a lot, in Advance for your help.

Cheers,
Swamy
Nathaniel Stoddard
Ranch Hand

Joined: May 29, 2003
Posts: 1258
Well, using the Map would be an in-memory operation (CPU-bound as they say), while the Database operation would be an IO operation (ergo, IO-bound). As you probably know, any IO stuff a computer does is slow[er]. So, it would definitely be more efficient (memory-wise) to use the in-memory Map at that point.

There are probably other issues though, if you're asking this question at all.


Nathaniel Stodard<br />SCJP, SCJD, SCWCD, SCBCD, SCDJWS, ICAD, ICSD, ICED
Stan James
(instanceof Sidekick)
Ranch Hand

Joined: Jan 29, 2003
Posts: 8791
We cache things from the database into maps in memory all the time. Every time it's a gamble that the peformance improvement is worth the memory cost. If we run out of memory, we may have bet too much on caching.

If the data is not totally static - unchanging between system restarts - we need a way to clear or reload the cached data. We went to some effort with a web UI and an API to make this work across a cluster of servers.


A good question is never answered. It is not a bolt to be tightened into place but a seed to be planted and to bear more seed toward the hope of greening the landscape of the idea. John Ciardi
Ramaswamy Srinivasan
Ranch Hand

Joined: Aug 31, 2004
Posts: 295
Pals,

Many a thanks to you.

Got the idea.

Cheers,
Swamy
William Brogden
Author and all-around good cowpoke
Rancher

Joined: Mar 22, 2000
Posts: 12759
    
    5
Some references on caching:
http://jcache.sourceforge.net/ <- generalized caching ref JSR 107
https://whirlycache.dev.java.net/ <- recent release, claims great speed
Enjoy!
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Which one would be Optimal? ( Map Vs Data Base)
 
Similar Threads
Data Locking with a DB File.
From Memory or from DB?
XML vs. ???
Ajax and JSON requests in jsp
Displaying Location map on JFrame