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


Java Reference类代码示例

本文整理汇总了Java中java.lang.ref.Reference的典型用法代码示例。如果您正苦于以下问题:Java Reference类的具体用法?Java Reference怎么用?Java Reference使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。


Reference类属于java.lang.ref包,在下文中一共展示了Reference类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: getAndClearToCompute

import java.lang.ref.Reference; //导入依赖的package包/类
public static synchronized List<CreatorBasedLazyFixList> getAndClearToCompute(FileObject file) {
    List<Reference<CreatorBasedLazyFixList>> references = file2Creators.get(file);
    
    if (references == null) {
        return Collections.emptyList();
    }
    
    List<CreatorBasedLazyFixList> result = new ArrayList<CreatorBasedLazyFixList>();
    
    for (Reference<CreatorBasedLazyFixList> r : references) {
        CreatorBasedLazyFixList c = r.get();
        
        if (c != null) {
            result.add(c);
        }
    }
    
    references.clear();
    
    return result;
}
 
开发者ID:apache,项目名称:incubator-netbeans,代码行数:22,代码来源:LazyHintComputationFactory.java

示例2: processQueue

import java.lang.ref.Reference; //导入依赖的package包/类
/**
 * Removes weak keys from the map that have been enqueued
 * on the reference queue and are no longer in use.
 */
private static void processQueue(ReferenceQueue<Key> queue,
                                 ConcurrentHashMap<? extends
                                 WeakReference<Key>, ?> pdMap) {
    Reference<? extends Key> ref;
    while ((ref = queue.poll()) != null) {
        pdMap.remove(ref);
    }
}
 
开发者ID:lambdalab-mirror,项目名称:jdk8u-jdk,代码行数:13,代码来源:ProtectionDomain.java

示例3: testMemoryReleased

import java.lang.ref.Reference; //导入依赖的package包/类
@SuppressWarnings("ST_WRITE_TO_STATIC_FROM_INSTANCE_METHOD")
@RandomlyFails
public void testMemoryReleased() throws Exception {
    TimedWeakReference.TIMEOUT = 0;
    FileObject wd = FileUtil.toFileObject(getWorkDir());
    TestFileUtils.writeFile(wd, "pom.xml", "<project><modelVersion>4.0.0</modelVersion>"
            + "<groupId>g</groupId><artifactId>a</artifactId>"
            + "<version>0</version></project>");
    Project p = ProjectManager.getDefault().findProject(wd);
    ((NbMavenProjectImpl) p).attachUpdater();
    /* Want to avoid leaks even if this is not called for some reason:
    ((NbMavenProjectImpl) p).detachUpdater();
    */
    Reference<?> r = new WeakReference<Object>(p);
    p = null;

    Thread.sleep(5000); //something has changed and the reference only gets cleared after some time. added @RandomlyFails
    // if it keeps on failing regularly, it's a candidate for removal, the point of the test is unclear to me.
    
    assertGC("can release project after updater detached", r, Collections.singleton(wd));
}
 
开发者ID:apache,项目名称:incubator-netbeans,代码行数:22,代码来源:NbMavenProjectImplTest.java

示例4: equals

import java.lang.ref.Reference; //导入依赖的package包/类
@Override
public boolean equals(Object obj) {
	if (this == obj) {
		return true;
	}
	if (dead) {
		// Post-mortem cleanup looks for this specific Reference
		// instance
		return false;
	}
	if (!(obj instanceof Reference<?>)) {
		return false;
	}
	Object oA = get();
	Object oB = ((Reference<?>) obj).get();
	if (oA == oB) {
		return true;
	}
	if (oA == null || oB == null) {
		return false;
	}
	return oA.equals(oB);
}
 
开发者ID:how2j,项目名称:lazycat,代码行数:24,代码来源:ManagedConcurrentWeakHashMap.java

示例5: getAllDataShadows

import java.lang.ref.Reference; //导入依赖的package包/类
/** @return all active DataShadows or null */
private static synchronized List<BrokenDataShadow> getAllDataShadows() {
    if (allDataShadows == null || allDataShadows.isEmpty()) {
        return null;
    }
    
    List<BrokenDataShadow> ret = new ArrayList<BrokenDataShadow>(allDataShadows.size());
    Iterator<Set<Reference<BrokenDataShadow>>> it = allDataShadows.values ().iterator();
    while (it.hasNext()) {
        Set<Reference<BrokenDataShadow>> ref = it.next();
        Iterator<Reference<BrokenDataShadow>> refs = ref.iterator ();
        while (refs.hasNext ()) {
            Reference<BrokenDataShadow> r = refs.next ();
            BrokenDataShadow shadow = r.get();
            if (shadow != null) {
                ret.add(shadow);
            }
        }
    }
    
    return ret;
}
 
开发者ID:apache,项目名称:incubator-netbeans,代码行数:23,代码来源:BrokenDataShadow.java

示例6: findLiveManagers

import java.lang.ref.Reference; //导入依赖的package包/类
private synchronized Object findLiveManagers() {
    JavaElementFoldManager oneMgr = null;
    List<JavaElementFoldManager> result = null;
    
    for (Iterator<Reference<JavaElementFoldManager>> it = managers.iterator(); it.hasNext(); ) {
        Reference<JavaElementFoldManager> ref = it.next();
        JavaElementFoldManager fm = ref.get();
        if (fm == null) {
            it.remove();
            continue;
        }
        if (result != null) {
            result.add(fm);
        } else if (oneMgr != null) {
            result = new ArrayList<JavaElementFoldManager>(2);
            result.add(oneMgr);
            result.add(fm);
        } else {
            oneMgr = fm;
        }
    }
    return result != null ? result : oneMgr;
}
 
开发者ID:apache,项目名称:incubator-netbeans,代码行数:24,代码来源:JavaElementFoldManager.java

示例7: toNbTask

import java.lang.ref.Reference; //导入依赖的package包/类
NbTask toNbTask (ITask task) {
    NbTask nbTask = null;
    if (task != null) {
        synchronized (tasks) {
            Reference<NbTask> nbTaskRef = tasks.get(task);
            if (nbTaskRef != null) {
                nbTask = nbTaskRef.get();
            }
            if (nbTask == null) {
                nbTask = new NbTask(task);
                tasks.put(task, new SoftReference<NbTask>(nbTask));
            }
        }
    }
    return nbTask;
}
 
开发者ID:apache,项目名称:incubator-netbeans,代码行数:17,代码来源:MylynSupport.java

示例8: testCleanupSecret

import java.lang.ref.Reference; //导入依赖的package包/类
static void testCleanupSecret(String algorithm) throws Exception {
    KeyGenerator desGen = KeyGenerator.getInstance(algorithm, SunJCEProvider);
    SecretKey key = desGen.generateKey();

    // Break into the implementation to observe the key byte array.
    Class<?> keyClass = key.getClass();
    Field keyField = keyClass.getDeclaredField("key");
    keyField.setAccessible(true);
    byte[] array = (byte[])keyField.get(key);

    byte[] zeros = new byte[array.length];
    do {
        // Wait for array to be cleared;  if not cleared test will timeout
        System.out.printf("%s array: %s%n", algorithm, Arrays.toString(array));
        key = null;
        System.gc();        // attempt to reclaim the key
    } while (Arrays.compare(zeros, array) != 0);
    System.out.printf("%s array: %s%n", algorithm, Arrays.toString(array));

    Reference.reachabilityFence(key); // Keep key alive
    Reference.reachabilityFence(array); // Keep array alive
}
 
开发者ID:AdoptOpenJDK,项目名称:openjdk-jdk10,代码行数:23,代码来源:DESKeyCleanupTest.java

示例9: detach

import java.lang.ref.Reference; //导入依赖的package包/类
private Task detach() {
        Task t;
        synchronized (allSessions) {
            Reference<ShellSession> refS = allSessions.get(consoleDocument);
            if (refS != null && refS.get() == this) {
                allSessions.remove(consoleDocument);
                detached = true;
            } else {
                return Task.EMPTY;
            }
        }
//        closed = true;
        model.detach();
        closed();
        if (exec != null) {
            FORCE_CLOSE_RP.post(this::forceCloseStreams, 300);
        }
        // leave the model
        gsm.getGuardedSections().forEach((GuardedSection gs) -> gs.removeSection());
        return sendJShellClose();
    }
 
开发者ID:apache,项目名称:incubator-netbeans,代码行数:22,代码来源:ShellSession.java

示例10: testLookupsRelease

import java.lang.ref.Reference; //导入依赖的package包/类
public void testLookupsRelease() {
    int idA = System.identityHashCode(MimeLookup.getLookup(MimePath.get("text/x-java")));

    TestUtilities.consumeAllMemory();
    TestUtilities.gc();

    MimePath mp = MimePath.get("text/x-java");
    Object obj = MimeLookup.getLookup(mp);
    int idB = System.identityHashCode(obj);
    assertEquals("Lookup instance was lost", idA, idB);
    
    // Force the MimePath instance to be dropped from the list of recently used
    for (int i = 0; i < MimePath.MAX_LRU_SIZE; i++) {
        MimePath.get("text/x-nonsense-" + i);
    }

    Reference<Object> ref = new WeakReference<Object>(obj);
    obj = null;
    mp = null;
    assertGC("Can disappear", ref);
    
    int idC = System.identityHashCode(MimeLookup.getLookup(MimePath.get("text/x-java")));
    assertTrue("Lookup instance was not released", idA != idC);
}
 
开发者ID:apache,项目名称:incubator-netbeans,代码行数:25,代码来源:MimeLookupMemoryGCTest.java

示例11: purge

import java.lang.ref.Reference; //导入依赖的package包/类
/**
 * Purges the specified reference
 * @param ref  the reference to purge
 * @return true or false
 */
boolean purge(final Reference<?> ref) {
    boolean r = parent.keyType != ReferenceStrength.HARD && key == ref;
    r = r || parent.valueType != ReferenceStrength.HARD && value == ref;
    if (r) {
        if (parent.keyType != ReferenceStrength.HARD) {
            ((Reference<?>) key).clear();
        }
        if (parent.valueType != ReferenceStrength.HARD) {
            ((Reference<?>) value).clear();
        } else if (parent.purgeValues) {
            value = null;
        }
    }
    return r;
}
 
开发者ID:funkemunky,项目名称:HCFCore,代码行数:21,代码来源:AbstractReferenceMap.java

示例12: getJavacApiJarClasspath

import java.lang.ref.Reference; //导入依赖的package包/类
private static ClassPath getJavacApiJarClasspath() {
    Reference<ClassPath> r = javacApiClasspath;
    ClassPath res = r.get();
    if (res != null) {
        return res;
    }
    if (r == NONE) {
        return null;
    }
    CodeSource codeSource = Modifier.class.getProtectionDomain().getCodeSource();
    URL javacApiJar = codeSource != null ? codeSource.getLocation() : null;
    if (javacApiJar != null) {
        Logger.getLogger(DeclarativeHintsParser.class.getName()).log(Level.FINE, "javacApiJar={0}", javacApiJar);
        File aj = FileUtil.archiveOrDirForURL(javacApiJar);
        if (aj != null) {
            res = ClassPathSupport.createClassPath(FileUtil.urlForArchiveOrDir(aj));
            javacApiClasspath = new WeakReference<>(res);
            return res;
        }
    }
    javacApiClasspath = NONE;
    return null;
}
 
开发者ID:apache,项目名称:incubator-netbeans,代码行数:24,代码来源:DeclarativeHintsParser.java

示例13: cleanUp

import java.lang.ref.Reference; //导入依赖的package包/类
/**
 * Repeatedly dequeues references from the queue and invokes {@link
 * FinalizableReference#finalizeReferent()} on them until the queue is empty. This method is a
 * no-op if the background thread was created successfully.
 */
void cleanUp() {
  if (threadStarted) {
    return;
  }

  Reference<?> reference;
  while ((reference = queue.poll()) != null) {
    /*
     * This is for the benefit of phantom references. Weak and soft references will have already
     * been cleared by this point.
     */
    reference.clear();
    try {
      ((FinalizableReference) reference).finalizeReferent();
    } catch (Throwable t) {
      logger.log(Level.SEVERE, "Error cleaning up after reference.", t);
    }
  }
}
 
开发者ID:s-store,项目名称:sstore-soft,代码行数:25,代码来源:FinalizableReferenceQueue.java

示例14: testNodeListenersDetachedAtFinalizeIssue58065

import java.lang.ref.Reference; //导入依赖的package包/类
public void testNodeListenersDetachedAtFinalizeIssue58065() throws Exception {
    CookieNode node = new CookieNode();
    SimpleCookieAction2 sca = new SimpleCookieAction2();
    Action action = sca.createContextAwareInstance(node.getLookup());
    
    class NodeListenerMemoryFilter implements MemoryFilter {
        public int numofnodelisteners = 0;
        public boolean reject(Object obj) {
            numofnodelisteners += (obj instanceof NodeListener)?1:0;
            return !((obj instanceof EventListenerList) | (obj instanceof Object[]));
        }
    }
    NodeListenerMemoryFilter filter = new NodeListenerMemoryFilter();
    assertSize("",Arrays.asList( new Object[] {node} ),1000000,filter);
    assertTrue("Node is expected to have a NodeListener attached", filter.numofnodelisteners > 0);
    
    Reference actionref = new WeakReference(sca);
    sca = null;
    action = null;
    assertGC("CookieAction is supposed to be GCed", actionref);
    
    NodeListenerMemoryFilter filter2 = new NodeListenerMemoryFilter();
    assertSize("",Arrays.asList( new Object[] {node} ),1000000,filter2);
    assertEquals("Node is expected to have no NodeListener attached", 0, filter2.numofnodelisteners);
}
 
开发者ID:apache,项目名称:incubator-netbeans,代码行数:26,代码来源:CookieAction2Test.java

示例15: testSourceForDocumentGCed

import java.lang.ref.Reference; //导入依赖的package包/类
public void testSourceForDocumentGCed() throws IOException {
    FileObject file = createFileObject("plain.txt", getName(), "\n");
    Document doc = openDocument(file);
    Source source = Source.create(doc);
    assertNotNull("No Source for " + doc, source);

    Reference<Source> sourceRef = new WeakReference<Source>(source);
    Reference<Document> docRef = new WeakReference<Document>(doc);
    Reference<FileObject> fileRef = new WeakReference<FileObject>(file);

    source = null;
    assertGC("Source can't be GCed", sourceRef);

    doc = null;
    assertGC("Document can't be GCed", docRef);

    file = null;
    assertGC("FileObject can't be GCed", fileRef);
}
 
开发者ID:apache,项目名称:incubator-netbeans,代码行数:20,代码来源:SourceTest.java


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