Code example for ReferenceQueue

0
 * 
 * @author iws 
 */ 
public class QueryCache { 
 
    private static ReferenceQueue queue = new ReferenceQueue();
    private static List<Query> queries = new ArrayList<Query>();
 
    static synchronized void addQuery(Query q) {
        queries.add(q);
        new QueryRef(q);
    } 
 
    static void clear() { 
        for (Query q: queries) q.clear();
    } 
 
    static void clean() { 
        while (true) { 
            Reference ref = queue.poll();
            if (ref == null) break;