本文整理汇总了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());
}
示例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());
}
示例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();
}
}
示例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();
}
}
示例5: removeCleanupReference
import java.lang.ref.PhantomReference; //导入方法依赖的package包/类
public static void removeCleanupReference(PhantomReference<Object> ref) {
if (ref == null) {
return;
}
REFERENCES.remove(ref);
ref.clear();
}
示例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);
}
示例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();
}
}