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

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

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

ConcurrentSkipListMap.tryReduceLevel介绍

[英]Possibly reduce head level if it has no nodes. This method can (rarely) make mistakes, in which case levels can disappear even though they are about to contain index nodes. This impacts performance, not correctness. To minimize mistakes as well as to reduce hysteresis, the level is reduced by one only if the topmost three levels look empty. Also, if the removed level looks non-empty after CAS, we try to change it back quick before anyone notices our mistake! (This trick works pretty well because this method will practically never make mistakes unless current thread stalls immediately before first CAS, in which case it is very unlikely to stall again immediately afterwards, so will recover.) We put up with all this rather than just let levels grow because otherwise, even a small map that has undergone a large number of insertions and removals will have a lot of levels, slowing down access more than would an occasional unwanted reduction.
[中]如果没有节点,可能会降低头部高度。这种方法可能(很少)出错,在这种情况下,级别可能会消失,即使它们即将包含索引节点。这会影响性能,而不是正确性。为了最大限度地减少错误并减少滞后,只有当最上面的三个级别看起来为空时,级别才会减少一。此外,如果移除的级别在CAS后看起来不是空的,我们会尝试在任何人注意到我们的错误之前快速将其更改回原来的级别!(这个技巧非常有效,因为这个方法几乎不会出错,除非当前线程在第一个CA之前立即暂停,在这种情况下,它不太可能在第一个CA之后立即再次暂停,因此将恢复。)我们忍受了所有这些,而不是仅仅让级别增加,因为否则,即使是一个经历了大量插入和删除的小地图也会有很多级别,比偶尔不必要的减少更会减慢访问速度。

代码示例

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

/**
 * Clears out index nodes associated with deleted first entry.
 */
private void clearIndexToFirst() {
  for (;;) {
    Index<K,V> q = head;
    for (;;) {
      Index<K,V> r = q.right;
      if (r != null && r.indexesDeletedNode() && !q.unlink(r))
        break;
      if ((q = q.down) == null) {
        if (head.right == null)
          tryReduceLevel();
        return;
      }
    }
  }
}

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

tryReduceLevel();

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

tryReduceLevel();

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

/**
 * Clears out index nodes associated with deleted first entry.
 */
private void clearIndexToFirst() {
  for (;;) {
    Index<K,V> q = head;
    for (;;) {
      Index<K,V> r = q.right;
      if (r != null && r.indexesDeletedNode() && !q.unlink(r))
        break;
      if ((q = q.down) == null) {
        if (head.right == null)
          tryReduceLevel();
        return;
      }
    }
  }
}

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

/**
 * Clears out index nodes associated with deleted first entry.
 */
private void clearIndexToFirst() {
  for (;;) {
    Index<K,V> q = head;
    for (;;) {
      Index<K,V> r = q.right;
      if (r != null && r.indexesDeletedNode() && !q.unlink(r))
        break;
      if ((q = q.down) == null) {
        if (head.right == null)
          tryReduceLevel();
        return;
      }
    }
  }
}

代码示例来源:origin: jtulach/bck2brwsr

/**
 * Clears out index nodes associated with deleted first entry.
 */
private void clearIndexToFirst() {
  for (;;) {
    Index<K,V> q = head;
    for (;;) {
      Index<K,V> r = q.right;
      if (r != null && r.indexesDeletedNode() && !q.unlink(r))
        break;
      if ((q = q.down) == null) {
        if (head.right == null)
          tryReduceLevel();
        return;
      }
    }
  }
}

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

/**
 * Clears out index nodes associated with deleted first entry.
 */
private void clearIndexToFirst() {
  for (;;) {
    Index<K,V> q = head;
    for (;;) {
      Index<K,V> r = q.right;
      if (r != null && r.indexesDeletedNode() && !q.unlink(r))
        break;
      if ((q = q.down) == null) {
        if (head.right == null)
          tryReduceLevel();
        return;
      }
    }
  }
}

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

/**
 * Clears out index nodes associated with deleted first entry.
 */
private void clearIndexToFirst() {
  for (;;) {
    Index<K,V> q = head;
    for (;;) {
      Index<K,V> r = q.right;
      if (r != null && r.indexesDeletedNode() && !q.unlink(r))
        break;
      if ((q = q.down) == null) {
        if (head.right == null)
          tryReduceLevel();
        return;
      }
    }
  }
}

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

/**
 * Clears out index nodes associated with deleted first entry.
 */
private void clearIndexToFirst() {
  for (;;) {
    Index<K,V> q = head;
    for (;;) {
      Index<K,V> r = q.right;
      if (r != null && r.indexesDeletedNode() && !q.unlink(r))
        break;
      if ((q = q.down) == null) {
        if (head.right == null)
          tryReduceLevel();
        return;
      }
    }
  }
}

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

/**
 * Clears out index nodes associated with deleted first entry.
 */
private void clearIndexToFirst() {
  for (;;) {
    Index<K,V> q = head;
    for (;;) {
      Index<K,V> r = q.right;
      if (r != null && r.indexesDeletedNode() && !q.unlink(r))
        break;
      if ((q = q.down) == null) {
        if (head.right == null)
          tryReduceLevel();
        return;
      }
    }
  }
}

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

/**
 * Clears out index nodes associated with deleted first entry.
 */
private void clearIndexToFirst() {
  for (;;) {
    Index<K,V> q = head;
    for (;;) {
      Index<K,V> r = q.right;
      if (r != null && r.indexesDeletedNode() && !q.unlink(r))
        break;
      if ((q = q.down) == null) {
        if (head.right == null)
          tryReduceLevel();
        return;
      }
    }
  }
}

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

/**
 * Clears out index nodes associated with deleted first entry.
 */
private void clearIndexToFirst() {
  for (;;) {
    Index<K,V> q = head;
    for (;;) {
      Index<K,V> r = q.right;
      if (r != null && r.indexesDeletedNode() && !q.unlink(r))
        break;
      if ((q = q.down) == null) {
        if (head.right == null)
          tryReduceLevel();
        return;
      }
    }
  }
}

代码示例来源:origin: FlexoVM/flexovm

/**
 * Clears out index nodes associated with deleted first entry.
 */
private void clearIndexToFirst() {
  for (;;) {
    Index<K,V> q = head;
    for (;;) {
      Index<K,V> r = q.right;
      if (r != null && r.indexesDeletedNode() && !q.unlink(r))
        break;
      if ((q = q.down) == null) {
        if (head.right == null)
          tryReduceLevel();
        return;
      }
    }
  }
}

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

tryReduceLevel();

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

tryReduceLevel();

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

tryReduceLevel();

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

tryReduceLevel();

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

tryReduceLevel();

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

tryReduceLevel();

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

tryReduceLevel();

相关文章

微信公众号

最新文章

更多

ConcurrentSkipListMap类方法