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?
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?
"Any fool can write code that a computer can understand. Good programmers write code that humans can understand." --- Martin Fowler
Please correct my English.
Joined: Jan 15, 2007
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.
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