当前位置: 首页>>代码示例>>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;未经允许,请勿转载。