• 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 Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

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

 
Ranch Hand
Posts: 295
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
 
Ranch Hand
Posts: 1258
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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.
 
(instanceof Sidekick)
Posts: 8791
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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.
 
Ramaswamy Srinivasan
Ranch Hand
Posts: 295
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Pals,

Many a thanks to you.

Got the idea.

Cheers,
Swamy
 
Author and all-around good cowpoke
Posts: 13078
6
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Some references on caching:
http://jcache.sourceforge.net/ <- generalized caching ref JSR 107
https://whirlycache.dev.java.net/ <- recent release, claims great speed
Enjoy!
 
Do you want ants? Because that's how you get ants. And a tiny ads:
a bit of art, as a gift, that will fit in a stocking
https://gardener-gift.com
reply
    Bookmark Topic Watch Topic
  • New Topic