當前位置: 首頁>>代碼示例>>Java>>正文


Java PhantomReference.clear方法代碼示例

本文整理匯總了Java中java.lang.ref.PhantomReference.clear方法的典型用法代碼示例。如果您正苦於以下問題:Java PhantomReference.clear方法的具體用法?Java PhantomReference.clear怎麽用?Java PhantomReference.clear使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在java.lang.ref.PhantomReference的用法示例。


在下文中一共展示了PhantomReference.clear方法的7個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。

示例1: test_clear

import java.lang.ref.PhantomReference; //導入方法依賴的package包/類
/**
 * @tests java.lang.ref.Reference#clear()
 */
@TestTargetNew(
    level = TestLevel.COMPLETE,
    notes = "",
    method = "clear",
    args = {}
)
public void test_clear() {
    tmpA = new Object();
    tmpB = new Object();
    tmpC = new Object();
    SoftReference sr = new SoftReference(tmpA, new ReferenceQueue());
    WeakReference wr = new WeakReference(tmpB, new ReferenceQueue());
    PhantomReference pr = new PhantomReference(tmpC, new ReferenceQueue());
    assertTrue("Start: Object not cleared.", (sr.get() != null)
            && (wr.get() != null));
    assertNull("Referent is not null.", pr.get());
    sr.clear();
    wr.clear();
    pr.clear();
    assertTrue("End: Object cleared.", (sr.get() == null)
            && (wr.get() == null));
    assertNull("Referent is not null.", pr.get());
    // Must reference tmpA and tmpB so the jit does not optimize them away
    assertTrue("should always pass", tmpA != sr.get() && tmpB != wr.get());
}
 
開發者ID:keplersj,項目名稱:In-the-Box-Fork,代碼行數:29,代碼來源:ReferenceTest.java

示例2: test_get

import java.lang.ref.PhantomReference; //導入方法依賴的package包/類
/**
 * @tests java.lang.ref.PhantomReference#get()
 */
@TestTargetNew(
    level = TestLevel.COMPLETE,
    notes = "",
    method = "get",
    args = {}
)
public void test_get() {
    ReferenceQueue rq = new ReferenceQueue();
    bool = new Boolean(false);
    PhantomReference pr = new PhantomReference(bool, rq);
    assertNull("get() should return null.", pr.get());
    pr.enqueue();
    assertNull("get() should return null.", pr.get());
    pr.clear();
    assertNull("get() should return null.", pr.get());
}
 
開發者ID:keplersj,項目名稱:In-the-Box-Fork,代碼行數:20,代碼來源:PhantomReferenceTest.java

示例3: processDeadParsedQueries

import java.lang.ref.PhantomReference; //導入方法依賴的package包/類
private void processDeadParsedQueries() throws IOException {
    PhantomReference deadQuery;
    while ((deadQuery = (PhantomReference)parsedQueryCleanupQueue.poll()) != null)
    {
        String statementName = (String)parsedQueryMap.remove(deadQuery);
        sendCloseStatement(statementName);
        deadQuery.clear();
    }
}
 
開發者ID:yngui,項目名稱:jephyr,代碼行數:10,代碼來源:QueryExecutorImpl.java

示例4: processDeadPortals

import java.lang.ref.PhantomReference; //導入方法依賴的package包/類
private void processDeadPortals() throws IOException {
    PhantomReference deadPortal;
    while ((deadPortal = (PhantomReference)openPortalCleanupQueue.poll()) != null)
    {
        String portalName = (String)openPortalMap.remove(deadPortal);
        sendClosePortal(portalName);
        deadPortal.clear();
    }
}
 
開發者ID:yngui,項目名稱:jephyr,代碼行數:10,代碼來源:QueryExecutorImpl.java

示例5: removeCleanupReference

import java.lang.ref.PhantomReference; //導入方法依賴的package包/類
public static void removeCleanupReference(PhantomReference<Object> ref) {
	if (ref == null) {
		return;
	}
	REFERENCES.remove(ref);
	ref.clear();
}
 
開發者ID:kenweezy,項目名稱:teiid,代碼行數:8,代碼來源:AutoCleanupUtil.java

示例6: testRegressionOverlayHelperLeak

import java.lang.ref.PhantomReference; //導入方法依賴的package包/類
/**
 * See <a href="http://opensource.atlassian.com/projects/spring/browse/RCP-492">RCP-492<a/>
 * for details on this test and related bug.
 *
 * @throws Exception
 */
public void testRegressionOverlayHelperLeak() throws Exception {
    // Basically, this test will simulate adding a component to a
    // JRootPane, then attach an overlay to it.  The overlay will be
    // installed into the layered pane of the JRootPane at the
    // PALETTE_LAYER.  This test will then remove the component from the
    // JRootPane, ensure the overlay is removed from the layered pane,
    // and then further ensure that nothing else holds a strong reference
    // to the component (by waiting for the component to be garbage
    // collected).
    JComponent component = createTestComponent();
    JComponent overlay = createTestOverlay();
    final ReferenceQueue rq = new ReferenceQueue();
    final PhantomReference componentRef = new PhantomReference(component, rq);

    final JRootPane rootPane = new JRootPane() {
        public boolean isVisible() {
            return true;
        }
        public boolean isShowing() {
            return true;
        }
        protected JLayeredPane createLayeredPane() {
            return new JLayeredPane() {
                public boolean isVisible() {
                    return true;
                }
                public boolean isShowing() {
                    return true;
                }
            };
        }
    };
    
    final int lpcount = rootPane.getLayeredPane().getComponentCountInLayer(JLayeredPane.PALETTE_LAYER.intValue());
    
    OverlayHelper.attachOverlay(overlay, component, 0, 0, 0);
    
    assertEquals(lpcount, rootPane.getLayeredPane().getComponentCountInLayer(JLayeredPane.PALETTE_LAYER.intValue()));
    rootPane.getContentPane().add(component);
    // updateOverlay is "invokedLater", so wait for it...
    waitUntilEventQueueIsEmpty();
    assertEquals(lpcount + 1, rootPane.getLayeredPane().getComponentCountInLayer(JLayeredPane.PALETTE_LAYER.intValue()));
    
    rootPane.getContentPane().remove(component);
    
    // the remove operation make be invoked later, so wait for it...
    waitUntilEventQueueIsEmpty();
    
    // Clear out our strong references so it gets garbage collected.
    component = null;
    overlay = null;
    
    // Make sure the overlay was removed from the layered pane.
    assertEquals("It appears the overlay was not removed from the layered pane when its component was removed from the content pane", lpcount, rootPane.getLayeredPane().getComponentCountInLayer(JLayeredPane.PALETTE_LAYER.intValue()));
    
    // Make sure no other references are held... wait up to 15 seconds for
    // the object to be garbage collected.
    // Note: we may want to remove this section from the test as it
    // presumes the VM will garbage collect the reference fairly quickly
    // once a System.gc() is invoked.
    // There is no guarantee this will happen, so the assumption may be
    // faulty.  If it ends up being a problem, or starts yielding
    // inconsistent test results, then feel free to yank it.
    PhantomReference pr;
    final long end = System.currentTimeMillis() + 15000;
    do {
        System.gc();
    } while((pr = (PhantomReference)rq.remove(100)) == null && System.currentTimeMillis() < end);
    if(pr != null) {
        pr.clear();
    }
    assertSame("Either something else is still holding a strong reference to the component, or the VM is not garbage collecting it.  See comments in OverlayHelperTests.testRegressionOverlayHelperLeak() for more detail", pr, componentRef);
}
 
開發者ID:shevek,項目名稱:spring-rich-client,代碼行數:80,代碼來源:OverlayHelperTests.java

示例7: handleReleased

import java.lang.ref.PhantomReference; //導入方法依賴的package包/類
/**
 * Removes the released collection from the garbage collection reference tracker, since this
 * connection is being release via a normal close method.
 *
 * @param interceptor    ignored
 * @param connectionInfo the connection that was released
 * @param action         ignored
 */
public void handleReleased(final ConnectionTrackingInterceptor interceptor, final ConnectionInfo connectionInfo, final ConnectionReturnAction action) {
    final PhantomReference phantomReference = references.remove(connectionInfo.getManagedConnectionInfo());
    if (phantomReference != null) {
        phantomReference.clear();
    }
}
 
開發者ID:apache,項目名稱:tomee,代碼行數:15,代碼來源:AutoConnectionTracker.java


注:本文中的java.lang.ref.PhantomReference.clear方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。