请问checkQueue()方法是什么意思?为什么运行结果inq的值为空?

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=new
LinkedList<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()方法里 “可用引用对象” 说的是什么,就解析

aluckdog
浏览 126回答 1
1回答

小唯快跑啊

写这段代码的需求是什么,功能逻辑又是什么。public class ReferenceQueue<T> extends ObjectReference queues, to which registered reference objects are appended by thegarbage collector after the appropriate reachability changes are detected.Reference<? extends T>poll()Polls this queue to see if a reference object is available.
打开App,查看更多内容
随时随地看视频慕课网APP

相关分类

Java