本文整理汇总了Java中java.lang.ref.Reference.clear方法的典型用法代码示例。如果您正苦于以下问题:Java Reference.clear方法的具体用法?Java Reference.clear怎么用?Java Reference.clear使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类java.lang.ref.Reference
的用法示例。
在下文中一共展示了Reference.clear方法的7个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: cleanUp
import java.lang.ref.Reference; //导入方法依赖的package包/类
/**
* Repeatedly dequeues references from the queue and invokes {@link
* FinalizableReference#finalizeReferent()} on them until the queue is empty. This method is a
* no-op if the background thread was created successfully.
*/
void cleanUp() {
if (threadStarted) {
return;
}
Reference<?> reference;
while ((reference = queue.poll()) != null) {
/*
* This is for the benefit of phantom references. Weak and soft references will have already
* been cleared by this point.
*/
reference.clear();
try {
((FinalizableReference) reference).finalizeReferent();
} catch (Throwable t) {
logger.log(Level.SEVERE, "Error cleaning up after reference.", t);
}
}
}
示例2: cleanUp
import java.lang.ref.Reference; //导入方法依赖的package包/类
/**
* Repeatedly dequeues references from the queue and invokes
* {@link FinalizableReference#finalizeReferent()} on them until the queue is empty. This method
* is a no-op if the background thread was created successfully.
*/
void cleanUp() {
if (threadStarted) {
return;
}
Reference<?> reference;
while ((reference = queue.poll()) != null) {
/*
* This is for the benefit of phantom references. Weak and soft references will have already
* been cleared by this point.
*/
reference.clear();
try {
((FinalizableReference) reference).finalizeReferent();
} catch (Throwable t) {
logger.log(Level.SEVERE, "Error cleaning up after reference.", t);
}
}
}
示例3: cleanUp
import java.lang.ref.Reference; //导入方法依赖的package包/类
/**
* Cleans up a single reference. Catches and logs all throwables.
* @return true if the caller should continue, false if the associated FinalizableReferenceQueue
* is no longer referenced.
*/
private boolean cleanUp(Reference<?> reference) {
Method finalizeReferentMethod = getFinalizeReferentMethod();
if (finalizeReferentMethod == null) {
return false;
}
do {
/*
* This is for the benefit of phantom references. Weak and soft
* references will have already been cleared by this point.
*/
reference.clear();
if (reference == frqReference) {
/*
* The client no longer has a reference to the
* FinalizableReferenceQueue. We can stop.
*/
return false;
}
try {
finalizeReferentMethod.invoke(reference);
} catch (Throwable t) {
logger.log(Level.SEVERE, "Error cleaning up after reference.", t);
}
/*
* Loop as long as we have references available so as not to waste
* CPU looking up the Method over and over again.
*/
} while ((reference = queue.poll()) != null);
return true;
}
示例4: cleanUp
import java.lang.ref.Reference; //导入方法依赖的package包/类
/**
* Cleans up a single reference. Catches and logs all throwables.
*
* @return true if the caller should continue, false if the associated FinalizableReferenceQueue
* is no longer referenced.
*/
private boolean cleanUp(Reference<?> reference) {
Method finalizeReferentMethod = getFinalizeReferentMethod();
if (finalizeReferentMethod == null) {
return false;
}
do {
/*
* This is for the benefit of phantom references. Weak and soft references will have already
* been cleared by this point.
*/
reference.clear();
if (reference == frqReference) {
/*
* The client no longer has a reference to the FinalizableReferenceQueue. We can stop.
*/
return false;
}
try {
finalizeReferentMethod.invoke(reference);
} catch (Throwable t) {
logger.log(Level.SEVERE, "Error cleaning up after reference.", t);
}
/*
* Loop as long as we have references available so as not to waste CPU looking up the Method
* over and over again.
*/
} while ((reference = queue.poll()) != null);
return true;
}
示例5: simulateValueReclamation
import java.lang.ref.Reference; //导入方法依赖的package包/类
/**
* Poke into the Cache internals to simulate garbage collection of the value associated with the
* given key. This assumes that the associated entry is a WeakValueReference or a
* SoftValueReference (and not a LoadingValueReference), and throws an IllegalStateException
* if that assumption does not hold.
*/
@SuppressWarnings("unchecked") // the instanceof check and the cast generate this warning
static <K, V> void simulateValueReclamation(Cache<K, V> cache, K key) {
ReferenceEntry<K, V> entry = getReferenceEntry(cache, key);
if (entry != null) {
ValueReference<K, V> valueRef = entry.getValueReference();
// fail on strong/computing refs
Preconditions.checkState(valueRef instanceof Reference);
Reference<V> ref = (Reference<V>) valueRef;
if (ref != null) {
ref.clear();
}
}
}
示例6: simulateKeyReclamation
import java.lang.ref.Reference; //导入方法依赖的package包/类
/**
* Poke into the Cache internals to simulate garbage collection of the given key. This assumes
* that the given entry is a weak or soft reference, and throws an IllegalStateException if that
* assumption does not hold.
*/
@SuppressWarnings("unchecked") // the instanceof check and the cast generate this warning
static <K, V> void simulateKeyReclamation(Cache<K, V> cache, K key) {
ReferenceEntry<K, V> entry = getReferenceEntry(cache, key);
Preconditions.checkState(entry instanceof Reference);
Reference<?> ref = (Reference<?>) entry;
if (ref != null) {
ref.clear();
}
}
示例7: runTests
import java.lang.ref.Reference; //导入方法依赖的package包/类
/********** test core **********/
protected void runTests() throws Exception {
targetClass = startToMain("ConstantPoolGCTarg").location().declaringType();
if (vm().canGetConstantPool()) {
byte[] cpbytes = targetClass.constantPool();
// imitate SoftReference cleared
Field constantPoolBytesRef = ReferenceTypeImpl.class.getDeclaredField("constantPoolBytesRef");
constantPoolBytesRef.setAccessible(true);
Reference softRef = (Reference) constantPoolBytesRef.get(targetClass);
softRef.clear();
byte[] cpbytes2 = targetClass.constantPool();
if (!Arrays.equals(cpbytes, cpbytes2)) {
failure("Consequent constantPool results vary, first was : " + cpbytes + ", now: " + cpbytes2);
};
} else {
System.out.println("can get constant pool version not supported");
}
/*
* resume until end
*/
listenUntilVMDisconnect();
/*
* deal with results of test
* if anything has called failure("foo") testFailed will be true
*/
if (!testFailed) {
println("ConstantPoolInfoGC: passed");
} else {
throw new Exception("ConstantPoolInfoGC: failed");
}
}