why PhantomReference does not work?
Demo code:

    import java.lang.ref.PhantomReference;
    import java.lang.ref.ReferenceQueue;
    
    public class Main {
    	public static void main(String[] args) throws InterruptedException {
    		Object test = new Object();
    		ReferenceQueue<Object> q = new ReferenceQueue<Object>();
    		PhantomReference<Object> p = new PhantomReference<Object>(test, q);
    		Object lock = new Object();
    		while (true) {
    			synchronized (lock) {
                                     //q.poll() is null always,why?
    				if (q.poll() != null) {
    					break;
    				}
    				//System.gc();
    				lock.wait();
    			}
    		}
    		System.out.println(1111111);
    	}
    }



I tested the code,but it always is dead loop.
The code (System.out.println(1111111);) can not execute,q.poll()  reurn null.

I think if test object is removed by GC,q.poll() will return p object,then break loop,but invoke this demo code,it is not like my thought 


why PhantomReference does not work?
===

Demo code:

    import java.lang.ref.PhantomReference;
    import java.lang.ref.ReferenceQueue;
    
    public class Main {
    	public static void main(String[] args) throws InterruptedException {
    		Object test = new Object();
    		ReferenceQueue<Object> q = new ReferenceQueue<Object>();
    		PhantomReference<Object> p = new PhantomReference<Object>(test, q);
    		Object lock = new Object();
    		while (true) {
    			synchronized (lock) {
                                     //q.poll() is null always,why?
    				if (q.poll() != null) {
    					break;
    				}
    				//System.gc();
    				lock.wait();
    			}
    		}
    		System.out.println(1111111);
    	}
    }



I tested the code,but it always is dead loop.
The code (System.out.println(1111111);) can not execute,q.poll()  reurn null.

I think if test object is removed by GC,q.poll() will return p object,then break loop,but invoke this demo code,it is not like my thought 

