本文整理汇总了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);
}
}
示例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;
}
示例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());
}
示例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;
}
}
}
示例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;
}
}
}
示例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()); }
}
}
}
示例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);
}
}
示例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);
}
示例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);
}
示例10: clearReferenceQueue
import java.lang.ref.ReferenceQueue; //导入方法依赖的package包/类
<T> void clearReferenceQueue(ReferenceQueue<T> referenceQueue) {
while (referenceQueue.poll() != null) {}
}
示例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;
}
}
}
}