java ReferenceQueue 分析

来源:互联网 发布:怎么卸载顽固软件 编辑:程序博客网 时间:2024/05/18 01:28

1、    public Reference<? extends T> poll() {
        if (head == null)
            return null;
 synchronized (lock) {
     return reallyPoll();
 }
    }//移除队列的一个元素------------马上返回

2、    public Reference<? extends T> remove(long timeout)
 throws IllegalArgumentException, InterruptedException
    {
 if (timeout < 0) {
     throw new IllegalArgumentException("Negative timeout value");
 }
 synchronized (lock) {
     Reference<? extends T> r = reallyPoll();
     if (r != null) return r;
     for (;;) {
  lock.wait(timeout);
  r = reallyPoll();
  if (r != null) return r;
  if (timeout != 0) return null;
     }
 }

 This method does not offer real-time guarantees: It schedules the
     * timeout as if by invoking the {@link Object#wait(long)} method


    }//移除队列所有的元素,阻塞直到有可用的元素----------并不保证实时有效

 

3、当对象被销毁的时候,reference对象并不会被销毁