Java Code Examples for java.lang.ref.ReferenceQueue#poll()

The following examples show how to use java.lang.ref.ReferenceQueue#poll() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: DefaultStyledDocument.java    From jdk8u_jdk with GNU General Public License v2.0 6 votes vote down vote up
/**
 * Return a list of stale change listeners.
 *
 * A change listener becomes "stale" when its document is cleaned by GC.
 */
static List<ChangeListener> getStaleListeners(ChangeListener l) {
    List<ChangeListener> staleListeners = new ArrayList<ChangeListener>();
    ReferenceQueue<DefaultStyledDocument> q = queueMap.get(l.getClass());

    if (q != null) {
        DocReference r;
        synchronized (q) {
            while ((r = (DocReference) q.poll()) != null) {
                staleListeners.add(r.getListener());
            }
        }
    }

    return staleListeners;
}
 
Example 2
Source File: DefaultStyledDocument.java    From openjdk-jdk8u-backup with GNU General Public License v2.0 6 votes vote down vote up
/**
 * Return a list of stale change listeners.
 *
 * A change listener becomes "stale" when its document is cleaned by GC.
 */
static List<ChangeListener> getStaleListeners(ChangeListener l) {
    List<ChangeListener> staleListeners = new ArrayList<ChangeListener>();
    ReferenceQueue<DefaultStyledDocument> q = queueMap.get(l.getClass());

    if (q != null) {
        DocReference r;
        synchronized (q) {
            while ((r = (DocReference) q.poll()) != null) {
                staleListeners.add(r.getListener());
            }
        }
    }

    return staleListeners;
}
 
Example 3
Source File: DefaultStyledDocument.java    From openjdk-jdk9 with GNU General Public License v2.0 6 votes vote down vote up
/**
 * Return a list of stale change listeners.
 *
 * A change listener becomes "stale" when its document is cleaned by GC.
 */
static List<ChangeListener> getStaleListeners(ChangeListener l) {
    List<ChangeListener> staleListeners = new ArrayList<ChangeListener>();
    ReferenceQueue<DefaultStyledDocument> q = queueMap.get(l.getClass());

    if (q != null) {
        DocReference r;
        synchronized (q) {
            while ((r = (DocReference) q.poll()) != null) {
                staleListeners.add(r.getListener());
            }
        }
    }

    return staleListeners;
}
 
Example 4
Source File: DefaultStyledDocument.java    From openjdk-jdk8u with GNU General Public License v2.0 6 votes vote down vote up
/**
 * Return a list of stale change listeners.
 *
 * A change listener becomes "stale" when its document is cleaned by GC.
 */
static List<ChangeListener> getStaleListeners(ChangeListener l) {
    List<ChangeListener> staleListeners = new ArrayList<ChangeListener>();
    ReferenceQueue<DefaultStyledDocument> q = queueMap.get(l.getClass());

    if (q != null) {
        DocReference r;
        synchronized (q) {
            while ((r = (DocReference) q.poll()) != null) {
                staleListeners.add(r.getListener());
            }
        }
    }

    return staleListeners;
}
 
Example 5
Source File: DefaultStyledDocument.java    From jdk8u-dev-jdk with GNU General Public License v2.0 6 votes vote down vote up
/**
 * Return a list of stale change listeners.
 *
 * A change listener becomes "stale" when its document is cleaned by GC.
 */
static List<ChangeListener> getStaleListeners(ChangeListener l) {
    List<ChangeListener> staleListeners = new ArrayList<ChangeListener>();
    ReferenceQueue<DefaultStyledDocument> q = queueMap.get(l.getClass());

    if (q != null) {
        DocReference r;
        synchronized (q) {
            while ((r = (DocReference) q.poll()) != null) {
                staleListeners.add(r.getListener());
            }
        }
    }

    return staleListeners;
}
 
Example 6
Source File: DefaultStyledDocument.java    From Java8CN with Apache License 2.0 6 votes vote down vote up
/**
 * Return a list of stale change listeners.
 *
 * A change listener becomes "stale" when its document is cleaned by GC.
 */
static List<ChangeListener> getStaleListeners(ChangeListener l) {
    List<ChangeListener> staleListeners = new ArrayList<ChangeListener>();
    ReferenceQueue<DefaultStyledDocument> q = queueMap.get(l.getClass());

    if (q != null) {
        DocReference r;
        synchronized (q) {
            while ((r = (DocReference) q.poll()) != null) {
                staleListeners.add(r.getListener());
            }
        }
    }

    return staleListeners;
}
 
Example 7
Source File: DefaultStyledDocument.java    From JDKSourceCode1.8 with MIT License 6 votes vote down vote up
/**
 * Return a list of stale change listeners.
 *
 * A change listener becomes "stale" when its document is cleaned by GC.
 */
static List<ChangeListener> getStaleListeners(ChangeListener l) {
    List<ChangeListener> staleListeners = new ArrayList<ChangeListener>();
    ReferenceQueue<DefaultStyledDocument> q = queueMap.get(l.getClass());

    if (q != null) {
        DocReference r;
        synchronized (q) {
            while ((r = (DocReference) q.poll()) != null) {
                staleListeners.add(r.getListener());
            }
        }
    }

    return staleListeners;
}
 
Example 8
Source File: ActionPropertyChangeListener.java    From openjdk-8 with GNU General Public License v2.0 5 votes vote down vote up
private void setTarget(T c) {
    ReferenceQueue<JComponent> queue = getQueue();
    // Check to see whether any old buttons have
    // been enqueued for GC.  If so, look up their
    // PCL instance and remove it from its Action.
    OwnedWeakReference<?> r;
    while ((r = (OwnedWeakReference)queue.poll()) != null) {
        ActionPropertyChangeListener<?> oldPCL = r.getOwner();
        Action oldAction = oldPCL.getAction();
        if (oldAction!=null) {
            oldAction.removePropertyChangeListener(oldPCL);
        }
    }
    this.target = new OwnedWeakReference<T>(c, queue, this);
}
 
Example 9
Source File: Thread.java    From openjdk-jdk8u with GNU General Public License v2.0 5 votes vote down vote up
/**
 * Removes from the specified map any keys that have been enqueued
 * on the specified reference queue.
 */
static void processQueue(ReferenceQueue<Class<?>> queue,
                         ConcurrentMap<? extends
                         WeakReference<Class<?>>, ?> map)
{
    Reference<? extends Class<?>> ref;
    while((ref = queue.poll()) != null) {
        map.remove(ref);
    }
}
 
Example 10
Source File: ActionPropertyChangeListener.java    From jdk8u-jdk with GNU General Public License v2.0 5 votes vote down vote up
private void setTarget(T c) {
    ReferenceQueue<JComponent> queue = getQueue();
    // Check to see whether any old buttons have
    // been enqueued for GC.  If so, look up their
    // PCL instance and remove it from its Action.
    OwnedWeakReference<?> r;
    while ((r = (OwnedWeakReference)queue.poll()) != null) {
        ActionPropertyChangeListener<?> oldPCL = r.getOwner();
        Action oldAction = oldPCL.getAction();
        if (oldAction!=null) {
            oldAction.removePropertyChangeListener(oldPCL);
        }
    }
    this.target = new OwnedWeakReference<T>(c, queue, this);
}
 
Example 11
Source File: ProtectionDomain.java    From openjdk-jdk9 with GNU General Public License v2.0 5 votes vote down vote up
/**
 * Removes weak keys from the map that have been enqueued
 * on the reference queue and are no longer in use.
 */
private static void processQueue(ReferenceQueue<Key> queue,
                                 ConcurrentHashMap<? extends
                                 WeakReference<Key>, ?> pdMap) {
    Reference<? extends Key> ref;
    while ((ref = queue.poll()) != null) {
        pdMap.remove(ref);
    }
}
 
Example 12
Source File: ObjectStreamClass.java    From jdk8u-dev-jdk with GNU General Public License v2.0 5 votes vote down vote up
/**
 * Removes from the specified map any keys that have been enqueued
 * on the specified reference queue.
 */
static void processQueue(ReferenceQueue<Class<?>> queue,
                         ConcurrentMap<? extends
                         WeakReference<Class<?>>, ?> map)
{
    Reference<? extends Class<?>> ref;
    while((ref = queue.poll()) != null) {
        map.remove(ref);
    }
}
 
Example 13
Source File: ObjectStreamClass.java    From jdk8u_jdk with GNU General Public License v2.0 5 votes vote down vote up
/**
 * Removes from the specified map any keys that have been enqueued
 * on the specified reference queue.
 */
static void processQueue(ReferenceQueue<Class<?>> queue,
                         ConcurrentMap<? extends
                         WeakReference<Class<?>>, ?> map)
{
    Reference<? extends Class<?>> ref;
    while((ref = queue.poll()) != null) {
        map.remove(ref);
    }
}
 
Example 14
Source File: ObjectStreamClass.java    From TencentKona-8 with GNU General Public License v2.0 5 votes vote down vote up
/**
 * Removes from the specified map any keys that have been enqueued
 * on the specified reference queue.
 */
static void processQueue(ReferenceQueue<Class<?>> queue,
                         ConcurrentMap<? extends
                         WeakReference<Class<?>>, ?> map)
{
    Reference<? extends Class<?>> ref;
    while((ref = queue.poll()) != null) {
        map.remove(ref);
    }
}
 
Example 15
Source File: ObjectStreamClass.java    From jdk8u-jdk with GNU General Public License v2.0 5 votes vote down vote up
/**
 * Removes from the specified map any keys that have been enqueued
 * on the specified reference queue.
 */
static void processQueue(ReferenceQueue<Class<?>> queue,
                         ConcurrentMap<? extends
                         WeakReference<Class<?>>, ?> map)
{
    Reference<? extends Class<?>> ref;
    while((ref = queue.poll()) != null) {
        map.remove(ref);
    }
}
 
Example 16
Source File: ProtectionDomain.java    From jdk8u-jdk with GNU General Public License v2.0 5 votes vote down vote up
/**
 * Removes weak keys from the map that have been enqueued
 * on the reference queue and are no longer in use.
 */
private static void processQueue(ReferenceQueue<Key> queue,
                                 ConcurrentHashMap<? extends
                                 WeakReference<Key>, ?> pdMap) {
    Reference<? extends Key> ref;
    while ((ref = queue.poll()) != null) {
        pdMap.remove(ref);
    }
}
 
Example 17
Source File: ActionPropertyChangeListener.java    From openjdk-8-source with GNU General Public License v2.0 5 votes vote down vote up
private void setTarget(T c) {
    ReferenceQueue<JComponent> queue = getQueue();
    // Check to see whether any old buttons have
    // been enqueued for GC.  If so, look up their
    // PCL instance and remove it from its Action.
    OwnedWeakReference<?> r;
    while ((r = (OwnedWeakReference)queue.poll()) != null) {
        ActionPropertyChangeListener<?> oldPCL = r.getOwner();
        Action oldAction = oldPCL.getAction();
        if (oldAction!=null) {
            oldAction.removePropertyChangeListener(oldPCL);
        }
    }
    this.target = new OwnedWeakReference<T>(c, queue, this);
}
 
Example 18
Source File: Thread.java    From jdk8u-dev-jdk with GNU General Public License v2.0 5 votes vote down vote up
/**
 * Removes from the specified map any keys that have been enqueued
 * on the specified reference queue.
 */
static void processQueue(ReferenceQueue<Class<?>> queue,
                         ConcurrentMap<? extends
                         WeakReference<Class<?>>, ?> map)
{
    Reference<? extends Class<?>> ref;
    while((ref = queue.poll()) != null) {
        map.remove(ref);
    }
}
 
Example 19
Source File: Thread.java    From jdk1.8-source-analysis with Apache License 2.0 5 votes vote down vote up
/**
 * Removes from the specified map any keys that have been enqueued
 * on the specified reference queue.
 */
static void processQueue(ReferenceQueue<Class<?>> queue,
                         ConcurrentMap<? extends
                         WeakReference<Class<?>>, ?> map)
{
    Reference<? extends Class<?>> ref;
    while((ref = queue.poll()) != null) {
        map.remove(ref);
    }
}
 
Example 20
Source File: CustomLevel.java    From openjdk-jdk9 with GNU General Public License v2.0 4 votes vote down vote up
private static void waitForGC(List<CustomLevelReference> customRefs,
                              ReferenceQueue<Level> queue)
     throws InterruptedException
{
    while (!customRefs.isEmpty()) {
        Reference<? extends Level> ref2;
        do {
            System.gc();
            Thread.sleep(100);
        } while ((ref2 = queue.poll()) == null);

        // Check garbage collected reference
        if (!customRefs.contains(ref2)) {
           throw new RuntimeException("Unexpected reference: " + ref2);
        }
        CustomLevelReference ref = customRefs.remove(customRefs.indexOf(ref2));
        System.out.println(ref2 + " garbage collected");
        final String name = ref.name;
        Level l;
        try {
            l = Level.parse(name);
            if (!name.equals("SEVERE")
                && !name.equals("INFO")
                || !name.equals(l.getName())) {
                throw new RuntimeException("Unexpected level "
                        + formatLevel(l));
            } else {
                if (l == Level.WARNING || l == Level.INFO
                        || l == Level.SEVERE) {
                    System.out.println("Level.parse found expected level: "
                            + formatLevel(l));
                } else {
                    throw new RuntimeException("Unexpected level "
                        + formatLevel(l));
                }
            }
        } catch (IllegalArgumentException iae) {
            if (!name.equals("WARNING")
                && !name.equals("INFO")
                && !name.equals("SEVERE")) {
                System.out.println("Level.parse fired expected exception: "
                    + iae);
            } else {
                throw iae;
            }
        }
    }
}