Code example for ReferenceQueue

0
import java.lang.ref.Reference; 
import java.lang.ref.ReferenceQueue; 
import java.util.Iterator; 
import java.util.Map; 
import java.util.Set; 
 
 
public class CleanUpThread <K,V>  extends Thread{
 
	ReferenceQueue<V> refQueue = new ReferenceQueue<V>();
	Map<K, V> cache = null;
	 
	public CleanUpThread(ReferenceQueue refQueue, Map softCache) {
		this.refQueue = refQueue;
	   	cache = softCache;
	} 
 
	@Override 
	public void run() { 
		// TODO Auto-generated method stub 
			while(true) { 
				try { 
					synchronized(cache) {
 
						Reference ref = refQueue.remove();