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


Java Reference.clear方法代碼示例

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


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

示例1: 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

示例2: 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:zugzug90,項目名稱:guava-mock,代碼行數:25,代碼來源:FinalizableReferenceQueue.java

示例3: cleanUp

import java.lang.ref.Reference; //導入方法依賴的package包/類
/**
 * Cleans up a single reference. Catches and logs all throwables.
 * @return true if the caller should continue, false if the associated FinalizableReferenceQueue
 * is no longer referenced.
 */
private boolean cleanUp(Reference<?> reference) {
  Method finalizeReferentMethod = getFinalizeReferentMethod();
  if (finalizeReferentMethod == null) {
    return false;
  }
  do {
    /*
     * This is for the benefit of phantom references. Weak and soft
     * references will have already been cleared by this point.
     */
    reference.clear();

    if (reference == frqReference) {
      /*
       * The client no longer has a reference to the
       * FinalizableReferenceQueue. We can stop.
       */
      return false;
    }

    try {
      finalizeReferentMethod.invoke(reference);
    } catch (Throwable t) {
      logger.log(Level.SEVERE, "Error cleaning up after reference.", t);
    }

    /*
     * Loop as long as we have references available so as not to waste
     * CPU looking up the Method over and over again.
     */
  } while ((reference = queue.poll()) != null);
  return true;
}
 
開發者ID:s-store,項目名稱:sstore-soft,代碼行數:39,代碼來源:Finalizer.java

示例4: cleanUp

import java.lang.ref.Reference; //導入方法依賴的package包/類
/**
 * Cleans up a single reference. Catches and logs all throwables.
 *
 * @return true if the caller should continue, false if the associated FinalizableReferenceQueue
 *     is no longer referenced.
 */
private boolean cleanUp(Reference<?> reference) {
  Method finalizeReferentMethod = getFinalizeReferentMethod();
  if (finalizeReferentMethod == null) {
    return false;
  }
  do {
    /*
     * This is for the benefit of phantom references. Weak and soft references will have already
     * been cleared by this point.
     */
    reference.clear();

    if (reference == frqReference) {
      /*
       * The client no longer has a reference to the FinalizableReferenceQueue. We can stop.
       */
      return false;
    }

    try {
      finalizeReferentMethod.invoke(reference);
    } catch (Throwable t) {
      logger.log(Level.SEVERE, "Error cleaning up after reference.", t);
    }

    /*
     * Loop as long as we have references available so as not to waste CPU looking up the Method
     * over and over again.
     */
  } while ((reference = queue.poll()) != null);
  return true;
}
 
開發者ID:zugzug90,項目名稱:guava-mock,代碼行數:39,代碼來源:Finalizer.java

示例5: simulateValueReclamation

import java.lang.ref.Reference; //導入方法依賴的package包/類
/**
 * Poke into the Cache internals to simulate garbage collection of the value associated with the
 * given key. This assumes that the associated entry is a WeakValueReference or a
 * SoftValueReference (and not a LoadingValueReference), and throws an IllegalStateException
 * if that assumption does not hold.
 */
@SuppressWarnings("unchecked")  // the instanceof check and the cast generate this warning
static <K, V> void simulateValueReclamation(Cache<K, V> cache, K key) {
  ReferenceEntry<K, V> entry = getReferenceEntry(cache, key);
  if (entry != null) {
    ValueReference<K, V> valueRef = entry.getValueReference();
    // fail on strong/computing refs
    Preconditions.checkState(valueRef instanceof Reference);
    Reference<V> ref = (Reference<V>) valueRef;
    if (ref != null) {
      ref.clear();
    }
  }
}
 
開發者ID:zugzug90,項目名稱:guava-mock,代碼行數:20,代碼來源:CacheTesting.java

示例6: simulateKeyReclamation

import java.lang.ref.Reference; //導入方法依賴的package包/類
/**
 * Poke into the Cache internals to simulate garbage collection of the given key. This assumes
 * that the given entry is a weak or soft reference, and throws an IllegalStateException if that
 * assumption does not hold.
 */
@SuppressWarnings("unchecked")  // the instanceof check and the cast generate this warning
static <K, V> void simulateKeyReclamation(Cache<K, V> cache, K key) {
  ReferenceEntry<K, V> entry = getReferenceEntry(cache, key);

  Preconditions.checkState(entry instanceof Reference);
  Reference<?> ref = (Reference<?>) entry;
  if (ref != null) {
    ref.clear();
  }
}
 
開發者ID:zugzug90,項目名稱:guava-mock,代碼行數:16,代碼來源:CacheTesting.java

示例7: runTests

import java.lang.ref.Reference; //導入方法依賴的package包/類
/********** test core **********/

    protected void runTests() throws Exception {
        targetClass = startToMain("ConstantPoolGCTarg").location().declaringType();

        if (vm().canGetConstantPool()) {
            byte[] cpbytes = targetClass.constantPool();

            // imitate SoftReference cleared
            Field constantPoolBytesRef = ReferenceTypeImpl.class.getDeclaredField("constantPoolBytesRef");
            constantPoolBytesRef.setAccessible(true);
            Reference softRef = (Reference) constantPoolBytesRef.get(targetClass);
            softRef.clear();

            byte[] cpbytes2 = targetClass.constantPool();
            if (!Arrays.equals(cpbytes, cpbytes2)) {
                failure("Consequent constantPool results vary, first was : " + cpbytes + ", now: " + cpbytes2);
            };

        } else {
            System.out.println("can get constant pool version not supported");
        }


        /*
         * resume until end
         */
        listenUntilVMDisconnect();

        /*
         * deal with results of test
         * if anything has called failure("foo") testFailed will be true
         */
        if (!testFailed) {
            println("ConstantPoolInfoGC: passed");
        } else {
            throw new Exception("ConstantPoolInfoGC: failed");
        }
    }
 
開發者ID:AdoptOpenJDK,項目名稱:openjdk-jdk10,代碼行數:40,代碼來源:ConstantPoolInfoGC.java


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