當前位置: 首頁>>代碼示例>>Java>>正文


Java ReferenceQueue.poll方法代碼示例

本文整理匯總了Java中java.lang.ref.ReferenceQueue.poll方法的典型用法代碼示例。如果您正苦於以下問題:Java ReferenceQueue.poll方法的具體用法?Java ReferenceQueue.poll怎麽用?Java ReferenceQueue.poll使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在java.lang.ref.ReferenceQueue的用法示例。


在下文中一共展示了ReferenceQueue.poll方法的11個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。

示例1: processQueue

import java.lang.ref.ReferenceQueue; //導入方法依賴的package包/類
/**
 * 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);
    }
}
 
開發者ID:lambdalab-mirror,項目名稱:jdk8u-jdk,代碼行數:13,代碼來源:ProtectionDomain.java

示例2: getStaleListeners

import java.lang.ref.ReferenceQueue; //導入方法依賴的package包/類
/**
 * 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;
}
 
開發者ID:lambdalab-mirror,項目名稱:jdk8u-jdk,代碼行數:21,代碼來源:DefaultStyledDocument.java

示例3: testForceGC

import java.lang.ref.ReferenceQueue; //導入方法依賴的package包/類
public void testForceGC() {		
	List<Object> list1 = new LinkedList<Object>();
	List<SoftReference<OneMB[]>> references = new ArrayList<SoftReference<OneMB[]>>();

    ReferenceQueue<? super Object[]> refQ = new ReferenceQueue<Object>();

	// Allocate 20mb object arrays, wrapped in soft references
	for (int i = 0; i< referenceCount; i++) {
		OneMB[] objects = new OneMB[arraySize];
		for (int arrayIndex = 0; arrayIndex < arraySize; arrayIndex++) {
			objects[arrayIndex] = new OneMB();
		}

		SoftReference<OneMB[]> ref = new SoftReference<OneMB[]>(objects, refQ);
		references.add(ref);
	}
	
	while (!referencesGone(references)) {				
		// Run the heap OOM so all soft references will be cleared by the GC 
		list1.add(new Object());
	}
	
	// At least one soft reference has been cleared. Make list1 eligible for GC 
	list1 = null;
	
	// Check that the the cleared soft reference was added to the queue.
	while (null == refQ.poll());
}
 
開發者ID:AdoptOpenJDK,項目名稱:openjdk-systemtest,代碼行數:29,代碼來源:ForceGC.java

示例4: drainKeyReferenceQueue

import java.lang.ref.ReferenceQueue; //導入方法依賴的package包/類
@GuardedBy("this")
void drainKeyReferenceQueue(ReferenceQueue<K> keyReferenceQueue) {
  Reference<? extends K> ref;
  int i = 0;
  while ((ref = keyReferenceQueue.poll()) != null) {
    @SuppressWarnings("unchecked")
    E entry = (E) ref;
    map.reclaimKey(entry);
    if (++i == DRAIN_MAX) {
      break;
    }
  }
}
 
開發者ID:zugzug90,項目名稱:guava-mock,代碼行數:14,代碼來源:MapMakerInternalMap.java

示例5: drainValueReferenceQueue

import java.lang.ref.ReferenceQueue; //導入方法依賴的package包/類
@GuardedBy("this")
void drainValueReferenceQueue(ReferenceQueue<V> valueReferenceQueue) {
  Reference<? extends V> ref;
  int i = 0;
  while ((ref = valueReferenceQueue.poll()) != null) {
    @SuppressWarnings("unchecked")
    WeakValueReference<K, V, E> valueReference = (WeakValueReference<K, V, E>) ref;
    map.reclaimValue(valueReference);
    if (++i == DRAIN_MAX) {
      break;
    }
  }
}
 
開發者ID:zugzug90,項目名稱:guava-mock,代碼行數:14,代碼來源:MapMakerInternalMap.java

示例6: clean

import java.lang.ref.ReferenceQueue; //導入方法依賴的package包/類
public static void clean() {
	// Clean up all remaining pointers
	for(ReferenceQueue<RandomVariableCuda> vectorsToRecycleReferenceQueue : vectorsToRecycleReferenceQueueMap.values()) {
		Reference<? extends RandomVariableCuda> reference;
		while((reference = vectorsToRecycleReferenceQueue.poll()) != null) {
			final CUdeviceptr cuDevicePtr = vectorsInUseReferenceMap.remove(reference);
			logger.fine("Freeing device pointer " + cuDevicePtr + " from " + reference);
			try {
				deviceExecutor.submit(new Runnable() { public void run() {
					JCudaDriver.cuMemFree(cuDevicePtr);
				}}).get();
			} catch (InterruptedException | ExecutionException e) { throw new RuntimeException(e.getCause()); }
		}
	}
}
 
開發者ID:finmath,項目名稱:finmath-lib-cuda-extensions,代碼行數:16,代碼來源:RandomVariableCuda.java

示例7: processQueue

import java.lang.ref.ReferenceQueue; //導入方法依賴的package包/類
/**
 * 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);
    }
}
 
開發者ID:SunburstApps,項目名稱:OpenJSharp,代碼行數:14,代碼來源:ObjectStreamClass.java

示例8: removeAll

import java.lang.ref.ReferenceQueue; //導入方法依賴的package包/類
void removeAll(ReferenceQueue<?> q, int n) throws InterruptedException {
    for (int j = n; j--> 0; ) {
        if (q.poll() == null) {
            for (;;) {
                System.gc();
                if (q.remove(1000) != null)
                    break;
                System.out.printf(
                    "%d/%d unqueued references remaining%n", j, n);
            }
        }
    }
    check(q.poll() == null);
}
 
開發者ID:AdoptOpenJDK,項目名稱:openjdk-jdk10,代碼行數:15,代碼來源:GCRetention.java

示例9: setTarget

import java.lang.ref.ReferenceQueue; //導入方法依賴的package包/類
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);
}
 
開發者ID:lambdalab-mirror,項目名稱:jdk8u-jdk,代碼行數:16,代碼來源:ActionPropertyChangeListener.java

示例10: clearReferenceQueue

import java.lang.ref.ReferenceQueue; //導入方法依賴的package包/類
<T> void clearReferenceQueue(ReferenceQueue<T> referenceQueue) {
  while (referenceQueue.poll() != null) {}
}
 
開發者ID:zugzug90,項目名稱:guava-mock,代碼行數:4,代碼來源:MapMakerInternalMap.java

示例11: waitForGC

import java.lang.ref.ReferenceQueue; //導入方法依賴的package包/類
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;
            }
        }
    }
}
 
開發者ID:AdoptOpenJDK,項目名稱:openjdk-jdk10,代碼行數:49,代碼來源:CustomLevel.java


注:本文中的java.lang.ref.ReferenceQueue.poll方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。