當前位置: 首頁>>代碼示例>>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;未經允許,請勿轉載。