本文整理汇总了Java中java.lang.ref.PhantomReference.isEnqueued方法的典型用法代码示例。如果您正苦于以下问题:Java PhantomReference.isEnqueued方法的具体用法?Java PhantomReference.isEnqueued怎么用?Java PhantomReference.isEnqueued使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类java.lang.ref.PhantomReference
的用法示例。
在下文中一共展示了PhantomReference.isEnqueued方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: checkListWithReferences
import java.lang.ref.PhantomReference; //导入方法依赖的package包/类
public void checkListWithReferences(List<PhantomReference<Monkey>> list, String string) {
int count = 0;
for (PhantomReference<Monkey> reference : list) {
if (reference.isEnqueued()) {
count++;
}
}
System.out.println(String.format("The enqueue reference count is %d (%s GC was called)", count, string));
}
示例2: testSourceCleanAfterClassLoaderDispose
import java.lang.ref.PhantomReference; //导入方法依赖的package包/类
/**
* Verifies that the cache in {@link AbstractClassGenerator} SOURCE doesn't
* leak class definitions of classloaders that are no longer used.
*/
public void testSourceCleanAfterClassLoaderDispose() throws Throwable {
ClassLoader custom = new ClassLoader(this.getClass().getClassLoader()) {
@Override
public Class<?> loadClass(String name) throws ClassNotFoundException {
if (EA.class.getName().equals(name)) {
InputStream classStream = this.getClass().getResourceAsStream("/net/sf/cglib/proxy/EA.class");
byte[] classBytes;
try {
classBytes = toByteArray(classStream);
return this.defineClass(null, classBytes, 0, classBytes.length);
} catch (IOException e) {
return super.loadClass(name);
}
} else {
return super.loadClass(name);
}
}
};
PhantomReference<ClassLoader> clRef = new PhantomReference<ClassLoader>(custom,
new ReferenceQueue<ClassLoader>());
buildAdvised(custom);
custom = null;
for (int i = 0; i < 10; ++i) {
System.gc();
Thread.sleep(100);
if (clRef.isEnqueued()) {
break;
}
}
assertTrue("CGLIB should allow classloaders to be evicted. PhantomReference<ClassLoader> was not cleared after 10 gc cycles," +
"thus it is likely some cache is preventing the class loader to be garbage collected", clRef.isEnqueued());
}
示例3: test
import java.lang.ref.PhantomReference; //导入方法依赖的package包/类
public int test(Logger logger, String[] args) {
PhantomObject prObj = new PhantomObject(new String("This is test object name"), this);
ReferenceQueue rq = new ReferenceQueue();
PhantomReference pr = new PhantomReference(prObj, rq);
prObj = null;
int count = 0;
try {
while (!pr.isEnqueued() && count < 50) {
System.gc();
count++;
Thread.sleep(1000);
}
} catch (InterruptedException e) {
System.err.println("The process was interrupted");
return fail();
}
if (isFinalized != 1) {
System.err.println("Finalizer hasn't been executed.");
return fail();
} else {
System.err.println("Finalizer has been executed.");
return pass();
}
//pr.clear();
}