当前位置: 首页>>代码示例>>Java>>正文


Java PhantomReference.isEnqueued方法代码示例

本文整理汇总了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));
}
 
开发者ID:avedensky,项目名称:JavaRushTasks,代码行数:11,代码来源:Solution.java

示例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());

}
 
开发者ID:cglib,项目名称:cglib,代码行数:42,代码来源:TestEnhancer.java

示例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();

}
 
开发者ID:freeVM,项目名称:freeVM,代码行数:31,代码来源:Btest422.java


注:本文中的java.lang.ref.PhantomReference.isEnqueued方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。