Win a copy of Programmer's Guide to Java SE 8 Oracle Certified Associate (OCA) this week in the OCAJP forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Cache recover on failover

 
Damodar Mukhopadhyay
Ranch Hand
Posts: 98
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi Experts,
I need your advice on Cache recover machanishm if there is a JVM failover.
I am thinking to serializing the cache every time it is updated, but the problem is, it will write the entire object every time and wich is very expensive.

Could you please suggest me some technique to achive this?

Thank you!
 
Damodar Mukhopadhyay
Ranch Hand
Posts: 98
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Any help please?
 
Wouter Oet
Saloon Keeper
Posts: 2700
IntelliJ IDE Opera
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
PatienceIsAVirtue!

Serializing everything isn't an option since that will be a huge bottleneck. But what is exactly the problem? What is being cached? What kind of caching solution are you using? And why do you want cache recovery? Why not build the cache up as requests come in?
 
Damodar Mukhopadhyay
Ranch Hand
Posts: 98
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi Wouter,
I have a SingleTon class which has a HashMap.
The Hashmap is the Cache in my application and I want to serialize it so that if my application goes down for any reason I can able to repopulate the cache.

Thanks,
 
shalindra Singh Suryvanshee
Greenhorn
Posts: 25
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Please go through with following link if it can help you -
Serializing classes with hashmaps
 
Wouter Oet
Saloon Keeper
Posts: 2700
IntelliJ IDE Opera
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Oke but then why not rebuild the cache as the requests come in? Saves you a lot of added complexity.
 
Damodar Mukhopadhyay
Ranch Hand
Posts: 98
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Actually the values of the messages (which are in cache) are required for some calculation when a new request comes in.
That means the new requests/messages requires the old messages.
 
Wouter Oet
Saloon Keeper
Posts: 2700
IntelliJ IDE Opera
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Then it is not a cache. You could write a shutdown hook that writes everything to the disk but then in a hard failure (e.g. no electricity) then those messages will be lost.
If you really need it be always be available then you need to think about clustering and replication. However those aren't easy to implement and should only be used when
absolutely necessary.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic