当前位置: 首页>>代码示例>>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;未经允许,请勿转载。