package 容器深入研究;import java.lang.ref.*;import java.util.*;class VeryBig{private static final int SIZE=10000;private long[] la=new long[SIZE];private String ident;public VeryBig(String id){ident=id;}public String toString(){return ident;}protected void finalize(){System.out.println("Finalizing "+ident);}}public class References{private static ReferenceQueue<VeryBig> rq=new ReferenceQueue<VeryBig>();public static void checkQueue(){Reference<? extends VeryBig> inq=rq.poll();if(inq!=null)System.out.println("In queue: "+inq.get());}public static void main(String[] args){int size=10;if(args.length>0)size=new Integer(args[0]);LinkedList<SoftReference<VeryBig>> sa=newLinkedList<SoftReference<VeryBig>>();for(int i=0;i<size;i++){sa.add(new SoftReference<VeryBig>(new VeryBig("Soft "+i),rq));System.out.println("Just created: "+sa.getLast());checkQueue();}}}checkQueue()方法是什么意思??,为什么运行结果inq的值为空???我不太懂JDK里面关于ReferenceQueue类中poll()方法里 “可用引用对象” 说的是什么,就解析
1 回答
小唯快跑啊
TA贡献1863条经验 获得超2个赞
写这段代码的需求是什么,功能逻辑又是什么。
public class ReferenceQueue<T> extends Object
Reference queues, to which registered reference objects are appended by the
garbage collector after the appropriate reachability changes are detected.
Reference<? extends T>
poll()
Polls this queue to see if a reference object is available.
添加回答
举报
0/150
提交
取消