Betty Rubble? Well, I would go with Betty... but I'd be thinking of Wilma.
Extend from SoftReference. Make two SoftReferences "equal" if their contained CacheKey objects are "equal" and make the hashCode of a SoftReference be the same as the hashCode of its contained CacheKey object.Originally posted by peter coster:
How will the HashMap's get method cope with equals() and hashCode methods ? because they would be referring SoftReference objects instead of my own CacheKey objects. Or should I just extend from SoftRefence and make my own version?
Originally posted by Peter Chase:
Sorry to question one of the experts, but that's not right, is it?
Originally posted by Paul Clapham:
Which is pretty much like the code you posted, now that I stare at it for long enough. I don't like it either, but I can say why. When the referenced object disappears and all you're left with is the "shell" SoftReference object, then the hashCode changes and the meaning of equals changes. I don't like that. You could deal with the hashCode problem by storing it in an instance variable the first time you calculate it from the referenced object. The equals problem I don't know -- maybe you should reload the referenced object if it isn't there.
Well, you can delete a post, you know.Originally posted by peter coster:
edit: ignore please this was stupid
Originally posted by peter coster:
The equals is also corrected now, we are using softreferences, JMX is only used to trigger the cleanup of these softreferences.
Originally posted by Mr. C Lamont Gilbert:
A SoftReference cleans itself. Thats its whole purpose. There is a whole package 'java.lang.ref' for this type of stuff. Yet you use JMX. Its the proverbial axe to swat a fly from a friends forehead.
A soft reference will clean up its referrent when memory gets low, automatically. You do need to manage cleaning up the soft reference itself.
Also I think i mentioned that GC is tuneable and in turn it makes your cache tuneable.
[ June 10, 2006: Message edited by: Mr. C Lamont Gilbert ]
/* <a href="http://www.benjaminranck.com" target="_blank" rel="nofollow">http://www.benjaminranck.com</a> - <a href="http://bjamins.blogspot.com" target="_blank" rel="nofollow">http://bjamins.blogspot.com</a> */
pie. tiny ad:
Building a Better World in your Backyard by Paul Wheaton and Shawn Klassen-Koop
https://coderanch.com/wiki/718759/books/Building-World-Backyard-Paul-Wheaton
|