Code example for ReferenceQueue

Methods: remove

0
        long durationMillis = TimeUnit.NANOSECONDS.toMillis(durationNanos);
        assertTrue(durationMillis > 750 && durationMillis < 1250);
    } 
 
    public void testRemoveWithImmediateResultAndNoTimeout() throws Exception { 
        ReferenceQueue<Object> referenceQueue = new ReferenceQueue<Object>();
        enqueue(referenceQueue);
        assertNotNull(referenceQueue.remove());
    } 
 
    public void testRemoveWithImmediateResultAndTimeout() throws Exception { 
        ReferenceQueue<Object> referenceQueue = new ReferenceQueue<Object>();
        enqueue(referenceQueue);
        assertNotNull(referenceQueue.remove(1000));
    } 
 
    public void testRemoveWithDelayedResultAndNoTimeout() throws Exception { 
        ReferenceQueue<Object> referenceQueue = new ReferenceQueue<Object>();
        enqueueLater(referenceQueue, 500);
        long startNanos = System.nanoTime();
        referenceQueue.remove();