I've something like this
private Map<MyObj1, MyObj2> map = new WeakHashMap<MyObj1, MyObj2>();
... somewhere in the code ...
MyObj1 myObj1 = new MyObj1();
map.put(myObj1, new MyObj2();
...
myObj1 = null;
... somewhere else in a thread ... (I would like to pass to a checkThis(MyObj2) method the Value associated with the entry that was removed from the Map)
/* something like this maybe */
while (true) {
MyObj2 myObj2 = referenceQueue.remove().get();
checkThis(myObj2);
}
MyObj1 key might be removed when GC comes into play and there is no strong reference to it.
I'd like to pass to checkThis(MyObj2) the particular map-value Object associated with the key that was removed (maybe checking a ReferenceQueue?)
I can't figure out how to put this into code
EDIT: Sorry I badly expressed my question... I've change it.