java.util.concurrent.ConcurrentSkipListMap.findNode()方法的使用及代码示例

x33g5p2x  于2022-01-18 转载在 其他  
字(11.0k)|赞(0)|评价(0)|浏览(154)

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

ConcurrentSkipListMap.findNode介绍

[英]Returns node holding key or null if no such, clearing out any deleted nodes seen along the way. Repeatedly traverses at base-level looking for key starting at predecessor returned from findPredecessor, processing base-level deletions as encountered. Some callers rely on this side-effect of clearing deleted nodes. Restarts occur, at traversal step centered on node n, if: (1) After reading n's next field, n is no longer assumed predecessor b's current successor, which means that we don't have a consistent 3-node snapshot and so cannot unlink any subsequent deleted nodes encountered. (2) n's value field is null, indicating n is deleted, in which case we help out an ongoing structural deletion before retrying. Even though there are cases where such unlinking doesn't require restart, they aren't sorted out here because doing so would not usually outweigh cost of restarting. (3) n is a marker or n's predecessor's value field is null, indicating (among other possibilities) that findPredecessor returned a deleted node. We can't unlink the node because we don't know its predecessor, so rely on another call to findPredecessor to notice and return some earlier predecessor, which it will do. This check is only strictly needed at beginning of loop, (and the b.value check isn't strictly needed at all) but is done each iteration to help avoid contention with other threads by callers that will fail to be able to change links, and so will retry anyway. The traversal loops in doPut, doRemove, and findNear all include the same three kinds of checks. And specialized versions appear in findFirst, and findLast and their variants. They can't easily share code because each uses the reads of fields held in locals occurring in the orders they were performed.
[中]返回持有键的节点或null(如果没有),清除沿途看到的所有已删除节点。在基础级别重复遍历,查找从FindPrederAccessor返回的前置项开始的密钥,并在遇到时处理基础级别的删除。一些调用方依赖于清除已删除节点的这种副作用。在以节点n为中心的遍历步骤中,如果:(1)读取n的下一个字段后,n不再被假定为前置b的当前后继,则会重新启动,这意味着我们没有一致的3节点快照,因此无法取消遇到的任何后续已删除节点的链接。(2) n的值字段为null,表示n已被删除,在这种情况下,在重试之前,我们将帮助进行结构删除。即使在某些情况下,这样的断开连接不需要重新启动,这里也没有对它们进行分类,因为这样做通常不会超过重新启动的成本。(3) n是一个标记,或者n的前置值字段为null,表示(除其他可能性外)FindPreceducer返回了一个已删除的节点。我们无法取消该节点的链接,因为我们不知道它的前一个节点,所以依赖另一个对FindPrecessor的调用来通知并返回一些以前的前一个节点,它会这样做。此检查仅在循环开始时严格需要(并且根本不严格需要b.value检查),但每次迭代都会执行此检查,以帮助避免调用方与其他线程发生争用,这些调用方将无法更改链接,因此无论如何都会重试。doPut、doRemove和findNear中的遍历循环都包含相同的三种检查。专门的版本出现在findFirst和findLast及其变体中。他们不能轻松地共享代码,因为每个人都使用本地保存的字段的读取,这些字段按执行顺序发生。

代码示例

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

/**
 * Gets value for key using findNode.
 * @param okey the key
 * @return the value, or null if absent
 */
private V doGet(Object okey) {
  Comparable<? super K> key = comparable(okey);
  /*
   * Loop needed here and elsewhere in case value field goes
   * null just as it is about to be returned, in which case we
   * lost a race with a deletion, so must retry.
   */
  for (;;) {
    Node<K,V> n = findNode(key);
    if (n == null)
      return null;
    Object v = n.value;
    if (v != null)
      return (V)v;
  }
}

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

/**
 * {@inheritDoc}
 *
 * @throws ClassCastException if the specified key cannot be compared
 *         with the keys currently in the map
 * @throws NullPointerException if any of the arguments are null
 */
public boolean replace(K key, V oldValue, V newValue) {
  if (oldValue == null || newValue == null)
    throw new NullPointerException();
  Comparable<? super K> k = comparable(key);
  for (;;) {
    Node<K,V> n = findNode(k);
    if (n == null)
      return false;
    Object v = n.value;
    if (v != null) {
      if (!oldValue.equals(v))
        return false;
      if (n.casValue(v, newValue))
        return true;
    }
  }
}

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

/**
 * {@inheritDoc}
 *
 * @return the previous value associated with the specified key,
 *         or {@code null} if there was no mapping for the key
 * @throws ClassCastException if the specified key cannot be compared
 *         with the keys currently in the map
 * @throws NullPointerException if the specified key or value is null
 */
public V replace(K key, V value) {
  if (value == null)
    throw new NullPointerException();
  Comparable<? super K> k = comparable(key);
  for (;;) {
    Node<K,V> n = findNode(k);
    if (n == null)
      return null;
    Object v = n.value;
    if (v != null && n.casValue(v, value))
      return (V)v;
  }
}

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

findNode(key); // cleans up
return;
  findNode(key);
return;

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

break;
if (!n.appendMarker(f) || !b.casNext(n, f))
  findNode(key);                  // Retry via findNode
else {

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

Comparable<? super K> ck = comparable(key);
if (!n.appendMarker(f) || !b.casNext(n, f))
  findNode(ck);                  // Retry via findNode
else {

代码示例来源:origin: ibinti/bugvm

/**
 * Gets value for key using findNode.
 * @param okey the key
 * @return the value, or null if absent
 */
private V doGet(Object okey) {
  Comparable<? super K> key = comparable(okey);
  /*
   * Loop needed here and elsewhere in case value field goes
   * null just as it is about to be returned, in which case we
   * lost a race with a deletion, so must retry.
   */
  for (;;) {
    Node<K,V> n = findNode(key);
    if (n == null)
      return null;
    Object v = n.value;
    if (v != null)
      return (V)v;
  }
}

代码示例来源:origin: MobiVM/robovm

/**
 * Gets value for key using findNode.
 * @param okey the key
 * @return the value, or null if absent
 */
private V doGet(Object okey) {
  Comparable<? super K> key = comparable(okey);
  /*
   * Loop needed here and elsewhere in case value field goes
   * null just as it is about to be returned, in which case we
   * lost a race with a deletion, so must retry.
   */
  for (;;) {
    Node<K,V> n = findNode(key);
    if (n == null)
      return null;
    Object v = n.value;
    if (v != null)
      return (V)v;
  }
}

代码示例来源:origin: com.mobidevelop.robovm/robovm-rt

/**
 * Gets value for key using findNode.
 * @param okey the key
 * @return the value, or null if absent
 */
private V doGet(Object okey) {
  Comparable<? super K> key = comparable(okey);
  /*
   * Loop needed here and elsewhere in case value field goes
   * null just as it is about to be returned, in which case we
   * lost a race with a deletion, so must retry.
   */
  for (;;) {
    Node<K,V> n = findNode(key);
    if (n == null)
      return null;
    Object v = n.value;
    if (v != null)
      return (V)v;
  }
}

代码示例来源:origin: com.bugvm/bugvm-rt

/**
 * Gets value for key using findNode.
 * @param okey the key
 * @return the value, or null if absent
 */
private V doGet(Object okey) {
  Comparable<? super K> key = comparable(okey);
  /*
   * Loop needed here and elsewhere in case value field goes
   * null just as it is about to be returned, in which case we
   * lost a race with a deletion, so must retry.
   */
  for (;;) {
    Node<K,V> n = findNode(key);
    if (n == null)
      return null;
    Object v = n.value;
    if (v != null)
      return (V)v;
  }
}

代码示例来源:origin: org.apidesign.bck2brwsr/emul

/**
 * Gets value for key using findNode.
 * @param okey the key
 * @return the value, or null if absent
 */
private V doGet(Object okey) {
  Comparable<? super K> key = comparable(okey);
  /*
   * Loop needed here and elsewhere in case value field goes
   * null just as it is about to be returned, in which case we
   * lost a race with a deletion, so must retry.
   */
  for (;;) {
    Node<K,V> n = findNode(key);
    if (n == null)
      return null;
    Object v = n.value;
    if (v != null)
      return (V)v;
  }
}

代码示例来源:origin: com.jtransc/jtransc-rt

/**
 * Gets value for key using findNode.
 * @param okey the key
 * @return the value, or null if absent
 */
private V doGet(Object okey) {
  Comparable<? super K> key = comparable(okey);
  /*
   * Loop needed here and elsewhere in case value field goes
   * null just as it is about to be returned, in which case we
   * lost a race with a deletion, so must retry.
   */
  for (;;) {
    Node<K,V> n = findNode(key);
    if (n == null)
      return null;
    Object v = n.value;
    if (v != null)
      return (V)v;
  }
}

代码示例来源:origin: org.codehaus.jsr166-mirror/jsr166

/**
 * Gets value for key using findNode.
 * @param okey the key
 * @return the value, or null if absent
 */
private V doGet(Object okey) {
  Comparable<? super K> key = comparable(okey);
  /*
   * Loop needed here and elsewhere in case value field goes
   * null just as it is about to be returned, in which case we
   * lost a race with a deletion, so must retry.
   */
  for (;;) {
    Node<K,V> n = findNode(key);
    if (n == null)
      return null;
    Object v = n.value;
    if (v != null)
      return (V)v;
  }
}

代码示例来源:origin: com.gluonhq/robovm-rt

/**
 * Gets value for key using findNode.
 * @param okey the key
 * @return the value, or null if absent
 */
private V doGet(Object okey) {
  Comparable<? super K> key = comparable(okey);
  /*
   * Loop needed here and elsewhere in case value field goes
   * null just as it is about to be returned, in which case we
   * lost a race with a deletion, so must retry.
   */
  for (;;) {
    Node<K,V> n = findNode(key);
    if (n == null)
      return null;
    Object v = n.value;
    if (v != null)
      return (V)v;
  }
}

代码示例来源:origin: MobiVM/robovm

/**
 * {@inheritDoc}
 *
 * @return the previous value associated with the specified key,
 *         or {@code null} if there was no mapping for the key
 * @throws ClassCastException if the specified key cannot be compared
 *         with the keys currently in the map
 * @throws NullPointerException if the specified key or value is null
 */
public V replace(K key, V value) {
  if (value == null)
    throw new NullPointerException();
  Comparable<? super K> k = comparable(key);
  for (;;) {
    Node<K,V> n = findNode(k);
    if (n == null)
      return null;
    Object v = n.value;
    if (v != null && n.casValue(v, value))
      return (V)v;
  }
}

代码示例来源:origin: org.codehaus.jsr166-mirror/jsr166

/**
 * {@inheritDoc}
 *
 * @return the previous value associated with the specified key,
 *         or <tt>null</tt> if there was no mapping for the key
 * @throws ClassCastException if the specified key cannot be compared
 *         with the keys currently in the map
 * @throws NullPointerException if the specified key or value is null
 */
public V replace(K key, V value) {
  if (value == null)
    throw new NullPointerException();
  Comparable<? super K> k = comparable(key);
  for (;;) {
    Node<K,V> n = findNode(k);
    if (n == null)
      return null;
    Object v = n.value;
    if (v != null && n.casValue(v, value))
      return (V)v;
  }
}

代码示例来源:origin: com.gluonhq/robovm-rt

/**
 * {@inheritDoc}
 *
 * @return the previous value associated with the specified key,
 *         or {@code null} if there was no mapping for the key
 * @throws ClassCastException if the specified key cannot be compared
 *         with the keys currently in the map
 * @throws NullPointerException if the specified key or value is null
 */
public V replace(K key, V value) {
  if (value == null)
    throw new NullPointerException();
  Comparable<? super K> k = comparable(key);
  for (;;) {
    Node<K,V> n = findNode(k);
    if (n == null)
      return null;
    Object v = n.value;
    if (v != null && n.casValue(v, value))
      return (V)v;
  }
}

代码示例来源:origin: com.bugvm/bugvm-rt

/**
 * {@inheritDoc}
 *
 * @return the previous value associated with the specified key,
 *         or {@code null} if there was no mapping for the key
 * @throws ClassCastException if the specified key cannot be compared
 *         with the keys currently in the map
 * @throws NullPointerException if the specified key or value is null
 */
public V replace(K key, V value) {
  if (value == null)
    throw new NullPointerException();
  Comparable<? super K> k = comparable(key);
  for (;;) {
    Node<K,V> n = findNode(k);
    if (n == null)
      return null;
    Object v = n.value;
    if (v != null && n.casValue(v, value))
      return (V)v;
  }
}

代码示例来源:origin: org.apidesign.bck2brwsr/emul

/**
 * {@inheritDoc}
 *
 * @return the previous value associated with the specified key,
 *         or <tt>null</tt> if there was no mapping for the key
 * @throws ClassCastException if the specified key cannot be compared
 *         with the keys currently in the map
 * @throws NullPointerException if the specified key or value is null
 */
public V replace(K key, V value) {
  if (value == null)
    throw new NullPointerException();
  Comparable<? super K> k = comparable(key);
  for (;;) {
    Node<K,V> n = findNode(k);
    if (n == null)
      return null;
    Object v = n.value;
    if (v != null && n.casValue(v, value))
      return (V)v;
  }
}

代码示例来源:origin: com.mobidevelop.robovm/robovm-rt

/**
 * {@inheritDoc}
 *
 * @return the previous value associated with the specified key,
 *         or {@code null} if there was no mapping for the key
 * @throws ClassCastException if the specified key cannot be compared
 *         with the keys currently in the map
 * @throws NullPointerException if the specified key or value is null
 */
public V replace(K key, V value) {
  if (value == null)
    throw new NullPointerException();
  Comparable<? super K> k = comparable(key);
  for (;;) {
    Node<K,V> n = findNode(k);
    if (n == null)
      return null;
    Object v = n.value;
    if (v != null && n.casValue(v, value))
      return (V)v;
  }
}

相关文章

ConcurrentSkipListMap类方法