java.lang.ref.Reference.clear()方法的使用及代码示例

x33g5p2x  于2022-01-28 转载在 其他  
字(7.2k)|赞(0)|评价(0)|浏览(91)

本文整理了Java中java.lang.ref.Reference.clear方法的一些代码示例,展示了Reference.clear的具体用法。这些代码示例主要来源于Github/Stackoverflow/Maven等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。Reference.clear方法的具体详情如下:
包路径:java.lang.ref.Reference
类名称:Reference
方法名:clear

Reference.clear介绍

[英]Makes the referent null. This does not force the reference object to be enqueued.
[中]使引用对象为空。这不会强制引用对象排队。

代码示例

代码示例来源:origin: commons-collections/commons-collections

boolean purge(Reference ref) {
    boolean r = (keyType > HARD) && (key == ref);
    r = r || ((valueType > HARD) && (value == ref));
    if (r) {
      if (keyType > HARD) ((Reference)key).clear();
      if (valueType > HARD) {
        ((Reference)value).clear();
      } else if (purgeValues) {
        value = null;
      }
    }
    return r;
  }
}

代码示例来源:origin: GitLqr/LQRWeChat

public void detachView() {
  if (mViewRef != null) {
    mViewRef.clear();
    mViewRef = null;
  }
}

代码示例来源:origin: GitLqr/LQRWeChat

public void detachView() {
  if (mViewRef != null) {
    mViewRef.clear();
    mViewRef = null;
  }
}

代码示例来源:origin: google/guava

/**
 * 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);
  }
 }
}

代码示例来源:origin: commons-collections/commons-collections

public Object setValue(Object object) {
  Object old = getValue();
  if (valueType > HARD) ((Reference)value).clear();
  value = toReference(valueType, object, hash);
  return old;
}

代码示例来源:origin: google/guava

reference.clear();

代码示例来源:origin: PipelineAI/pipeline

/**
 * Called from RequestVariable.shutdown() to unschedule the task.
 */
public void shutdown() {
  RequestBatch<BatchReturnType, ResponseType, RequestArgumentType> currentBatch = batch.getAndSet(null);
  if (currentBatch != null) {
    currentBatch.shutdown();
  }
  if (timerListenerReference.get() != null) {
    // if the timer was started we'll clear it so it stops ticking
    timerListenerReference.get().clear();
  }
}

代码示例来源:origin: wildfly/wildfly

public Object setValue(Object object) {
  Object old = getValue();
  if (valueType > HARD) ((Reference)value).clear();
  value = toReference(valueType, object, hash);
  return old;
}

代码示例来源:origin: prestodb/presto

/**
 * 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);
  }
 }
}

代码示例来源:origin: org.postgresql/postgresql

private void processDeadPortals() throws IOException {
 Reference<? extends Portal> deadPortal;
 while ((deadPortal = openPortalCleanupQueue.poll()) != null) {
  String portalName = openPortalMap.remove(deadPortal);
  sendClosePortal(portalName);
  deadPortal.clear();
 }
}

代码示例来源:origin: org.postgresql/postgresql

private void processDeadParsedQueries() throws IOException {
 Reference<? extends SimpleQuery> deadQuery;
 while ((deadQuery = parsedQueryCleanupQueue.poll()) != null) {
  String statementName = parsedQueryMap.remove(deadQuery);
  sendCloseStatement(statementName);
  deadQuery.clear();
 }
}

代码示例来源:origin: MorphiaOrg/morphia

public Object setValue(final Object object) {
  final Object old = getValue();
  if (valueType > HARD) {
    ((Reference) value).clear();
  }
  value = toReference(valueType, object, hash);
  return old;
}

代码示例来源:origin: google/guava

/**
 * 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();
 }
}

代码示例来源:origin: PipelineAI/pipeline

@Override
public void onError(Throwable e) {
  if (isNotTimedOut()) {
    // stop timer and pass notification through
    tl.clear();
    child.onError(e);
  }
}

代码示例来源:origin: PipelineAI/pipeline

@Override
public void onCompleted() {
  if (isNotTimedOut()) {
    // stop timer and pass notification through
    tl.clear();
    child.onCompleted();
  }
}

代码示例来源:origin: commons-collections/commons-collections

/**
 * Sets the value of the entry.
 * 
 * @param obj  the object to store
 * @return the previous value
 */
public Object setValue(Object obj) {
  Object old = getValue();
  if (parent.valueType > HARD) {
    ((Reference)value).clear();
  }
  value = toReference(parent.valueType, obj, hashCode);
  return old;
}

代码示例来源:origin: wildfly/wildfly

/**
 * Sets the value of the entry.
 * 
 * @param obj  the object to store
 * @return the previous value
 */
public Object setValue(Object obj) {
  Object old = getValue();
  if (parent.valueType > HARD) {
    ((Reference)value).clear();
  }
  value = toReference(parent.valueType, obj, hashCode);
  return old;
}

代码示例来源:origin: PipelineAI/pipeline

private void handleCommandEnd(boolean commandExecutionStarted) {
  Reference<TimerListener> tl = timeoutTimer.get();
  if (tl != null) {
    tl.clear();
  }
  long userThreadLatency = System.currentTimeMillis() - commandStartTimestamp;
  executionResult = executionResult.markUserThreadCompletion((int) userThreadLatency);
  if (executionResultAtTimeOfCancellation == null) {
    metrics.markCommandDone(executionResult, commandKey, threadPoolKey, commandExecutionStarted);
  } else {
    metrics.markCommandDone(executionResultAtTimeOfCancellation, commandKey, threadPoolKey, commandExecutionStarted);
  }
  if (endCurrentThreadExecutingCommand != null) {
    endCurrentThreadExecutingCommand.call();
  }
}

代码示例来源:origin: google/guava

/**
 * 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();
  }
 }
}

代码示例来源:origin: PipelineAI/pipeline

private void cleanUpAfterResponseFromCache(boolean commandExecutionStarted) {
  Reference<TimerListener> tl = timeoutTimer.get();
  if (tl != null) {
    tl.clear();
  }
  final long latency = System.currentTimeMillis() - commandStartTimestamp;
  executionResult = executionResult
      .addEvent(-1, HystrixEventType.RESPONSE_FROM_CACHE)
      .markUserThreadCompletion(latency)
      .setNotExecutedInThread();
  ExecutionResult cacheOnlyForMetrics = ExecutionResult.from(HystrixEventType.RESPONSE_FROM_CACHE)
      .markUserThreadCompletion(latency);
  metrics.markCommandDone(cacheOnlyForMetrics, commandKey, threadPoolKey, commandExecutionStarted);
  eventNotifier.markEvent(HystrixEventType.RESPONSE_FROM_CACHE, commandKey);
}

相关文章