aspose file tools*
The moose likes Java in General and the fly likes Cache recover on failover Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of EJB 3 in Action this week in the EJB and other Java EE Technologies forum!
JavaRanch » Java Forums » Java » Java in General
Bookmark "Cache recover on failover" Watch "Cache recover on failover" New topic
Author

Cache recover on failover

Damodar Mukhopadhyay
Ranch Hand

Joined: Jan 15, 2007
Posts: 98
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!

SCJP 1.5, SCWCD 1.4, SCBCD 5.0, next SCDJWS...
Damodar Mukhopadhyay
Ranch Hand

Joined: Jan 15, 2007
Posts: 98
Any help please?
Wouter Oet
Saloon Keeper

Joined: Oct 25, 2008
Posts: 2700

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?


"Any fool can write code that a computer can understand. Good programmers write code that humans can understand." --- Martin Fowler
Please correct my English.
Damodar Mukhopadhyay
Ranch Hand

Joined: Jan 15, 2007
Posts: 98
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

Joined: Aug 05, 2008
Posts: 25
Please go through with following link if it can help you -
Serializing classes with hashmaps

Regards
Shalindra Singh
SCJP, SCWCD
Wouter Oet
Saloon Keeper

Joined: Oct 25, 2008
Posts: 2700

Oke but then why not rebuild the cache as the requests come in? Saves you a lot of added complexity.
Damodar Mukhopadhyay
Ranch Hand

Joined: Jan 15, 2007
Posts: 98
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

Joined: Oct 25, 2008
Posts: 2700

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.
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Cache recover on failover
 
Similar Threads
Problems with thread exceeding cache size and garbage collection
Http Basic Authentication cached ?
Tomcat cache data
The 'Resend' issue.
How to use Singleton Design pattern in a Clustered Environment?