Code example for ReferenceQueue

Methods: remove

0
        enqueueLater(referenceQueue, 500);
        referenceQueue.remove(Long.MAX_VALUE);
    } 
 
    public void testRemoveWithSpuriousNotify() throws Exception { 
        final ReferenceQueue<Object> referenceQueue = new ReferenceQueue<Object>();
 
        runLater(new Runnable() {
            @Override public void run() { 
                synchronized (referenceQueue) {
                    referenceQueue.notifyAll();
                } 
            } 
        }, 500); 
 
        long startNanos = System.nanoTime();
        referenceQueue.remove(1000);
        long durationNanos = System.nanoTime() - startNanos;
        long durationMillis = TimeUnit.NANOSECONDS.toMillis(durationNanos);
        assertTrue(durationMillis > 750 && durationMillis < 1250);
    }