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

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

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

ConcurrentSkipListMap.putIfAbsent介绍

暂无

代码示例

代码示例来源:origin: lealone/Lealone

@Override
public V putIfAbsent(K key, V value) {
  setMaxKey(key);
  return skipListMap.putIfAbsent(key, value);
}

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

public V putIfAbsent(K key, V value) {
  checkKeyBounds(key);
  return m.putIfAbsent(key, value);
}

代码示例来源:origin: apache/ignite

/** {@inheritDoc} */
@Nullable @Override public V putIfAbsent(K k, V v) {
  A.notNull(k, "k", v, "v");
  V ret = super.putIfAbsent(k, v);
  // Handle size only if put succeeded.
  if (ret == null)
    onPut();
  return ret;
}

代码示例来源:origin: apache/hive

private TagState getTagState(String tag) {
 TagState state = tagInfo.get(tag);
 if (state == null) {
  state = new TagState(tag);
  TagState old = tagInfo.putIfAbsent(tag, state);
  state = (old == null) ? state : old;
 }
 return state;
}

代码示例来源:origin: lealone/Lealone

private void doWaitSpin() {
  // pick a random sleep interval based on the number of threads spinning, so that
  // we should always have a thread about to wake up, but most threads are sleeping
  long sleep = 10000L * pool.spinningCount.get();
  sleep = Math.min(1000000, sleep);
  sleep *= Math.random();
  sleep = Math.max(10000, sleep);
  long start = System.nanoTime();
  // place ourselves in the spinning collection; if we clash with another thread just exit
  Long target = start + sleep;
  if (pool.spinning.putIfAbsent(target, this) != null)
    return;
  LockSupport.parkNanos(sleep);
  // remove ourselves (if haven't been already) - we should be at or near the front, so should be cheap-ish
  pool.spinning.remove(target, this);
  // finish timing and grab spinningTime (before we finish timing so it is under rather than overestimated)
  long end = System.nanoTime();
  long spin = end - start;
  long stopCheck = pool.stopCheck.addAndGet(spin);
  maybeStop(stopCheck, end);
  if (prevStopCheck + spin == stopCheck)
    soleSpinnerSpinTime += spin;
  else
    soleSpinnerSpinTime = 0;
  prevStopCheck = stopCheck;
}

代码示例来源:origin: apache/incubator-gobblin

private void onStart(long startTime) {
  Long queueTime = queuedTasks.remove(this.underlyingTask.getTaskId());
  long workUnitCreationTime = this.underlyingTask.getTaskContext().getTaskState().getPropAsLong(ConfigurationKeys.WORK_UNIT_CREATION_TIME_IN_MILLIS, 0);
  long timeInQueue = startTime - queueTime;
  long timeSinceWorkUnitCreation = startTime - workUnitCreationTime;
  taskCreateAndRunTimer.update(timeSinceWorkUnitCreation, TimeUnit.MILLISECONDS);
  LOG.debug(String.format("Task %s started. Saving queued time of %d ms to history.", underlyingTask.getTaskId(), timeInQueue));
  queuedTaskTimeHistorical.putIfAbsent(System.currentTimeMillis(), timeInQueue);
  runningTaskCount.inc();
 }
}

代码示例来源:origin: apache/hbase

@VisibleForTesting
RegionStateNode createRegionStateNode(RegionInfo regionInfo) {
 RegionStateNode newNode = new RegionStateNode(regionInfo, regionInTransition);
 RegionStateNode oldNode = regionsMap.putIfAbsent(regionInfo.getRegionName(), newNode);
 return oldNode != null ? oldNode : newNode;
}

代码示例来源:origin: twitter/distributedlog

@Override
public void onSuccess(Set<URI> uris) {
  for (URI uri : uris) {
    if (subNamespaces.containsKey(uri)) {
      continue;
    }
    SubNamespace subNs = new SubNamespace(uri);
    if (null == subNamespaces.putIfAbsent(uri, subNs)) {
      subNs.watch();
      logger.info("Watched new sub namespace {}.", uri);
      notifyOnNamespaceChanges();
    }
  }
}

代码示例来源:origin: twitter/distributedlog

public FederatedZKLogMetadataStore(
    DistributedLogConfiguration conf,
    URI namespace,
    ZooKeeperClient zkc,
    OrderedScheduler scheduler) throws IOException {
  this.conf = conf;
  this.namespace = namespace;
  this.zkc = zkc;
  this.scheduler = scheduler;
  this.forceCheckLogExistence = conf.getFederatedCheckExistenceWhenCacheMiss();
  this.subNamespaces = new ConcurrentSkipListMap<URI, SubNamespace>();
  this.log2Locations = new ConcurrentHashMap<String, URI>();
  this.zkSubnamespacesPath = namespace.getPath() + "/" + ZNODE_SUB_NAMESPACES;
  this.maxLogsPerSubnamespace = conf.getFederatedMaxLogsPerSubnamespace();
  // fetch the sub namespace
  Set<URI> uris = FutureUtils.result(fetchSubNamespaces(this));
  for (URI uri : uris) {
    SubNamespace subNs = new SubNamespace(uri);
    if (null == subNamespaces.putIfAbsent(uri, subNs)) {
      subNs.watch();
      logger.info("Watched sub namespace {}", uri);
    }
  }
  logger.info("Federated ZK LogMetadataStore is initialized for {}", namespace);
}

代码示例来源:origin: apache/hbase

public RegionFailedOpen addToFailedOpen(final RegionStateNode regionNode) {
 final byte[] key = regionNode.getRegionInfo().getRegionName();
 RegionFailedOpen node = regionFailedOpen.get(key);
 if (node == null) {
  RegionFailedOpen newNode = new RegionFailedOpen(regionNode);
  RegionFailedOpen oldNode = regionFailedOpen.putIfAbsent(key, newNode);
  node = oldNode != null ? oldNode : newNode;
 }
 return node;
}

代码示例来源:origin: apache/hive

buffer.setTag(tag);
while (true) { // Overwhelmingly executes once, or maybe twice (replacing stale value).
 LlapDataBuffer oldVal = subCache.getCache().putIfAbsent(offset, buffer);
 if (oldVal == null) {

代码示例来源:origin: io.dropwizard.metrics/metrics-core

/**
 * Adds an old value with a fixed timestamp to the reservoir.
 *
 * @param value     the value to be added
 * @param timestamp the epoch timestamp of {@code value} in seconds
 */
public void update(long value, long timestamp) {
  rescaleIfNeeded();
  lockForRegularUsage();
  try {
    final double itemWeight = weight(timestamp - startTime);
    final WeightedSample sample = new WeightedSample(value, itemWeight);
    final double priority = itemWeight / ThreadLocalRandom.current().nextDouble();
    final long newCount = count.incrementAndGet();
    if (newCount <= size) {
      values.put(priority, sample);
    } else {
      Double first = values.firstKey();
      if (first < priority && values.putIfAbsent(priority, sample) == null) {
        // ensure we always remove an item
        while (values.remove(first) == null) {
          first = values.firstKey();
        }
      }
    }
  } finally {
    unlockForRegularUsage();
  }
}

代码示例来源:origin: oracle/helidon

/**
 * Adds an old value with a fixed timestamp to the reservoir.
 *
 * @param value     the value to be added
 * @param timestamp the epoch timestamp of {@code value} in seconds
 */
public void update(long value, long timestamp) {
  rescaleIfNeeded();
  lockForRegularUsage();
  try {
    final double itemWeight = weight(timestamp - startTime);
    final WeightedSnapshot.WeightedSample sample = new WeightedSnapshot.WeightedSample(value, itemWeight);
    final double priority = itemWeight / ThreadLocalRandom.current().nextDouble();
    final long newCount = count.incrementAndGet();
    if (newCount <= size) {
      values.put(priority, sample);
    } else {
      Double first = values.firstKey();
      if ((first < priority) && (values.putIfAbsent(priority, sample) == null)) {
        // ensure we always remove an item
        while (values.remove(first) == null) {
          first = values.firstKey();
        }
      }
    }
  } finally {
    unlockForRegularUsage();
  }
}

代码示例来源:origin: networknt/light-4j

/**
 * Adds an old value with a fixed timestamp to the reservoir.
 *
 * @param value     the value to be added
 * @param timestamp the epoch timestamp of {@code value} in seconds
 */
public void update(long value, long timestamp) {
  rescaleIfNeeded();
  lockForRegularUsage();
  try {
    final double itemWeight = weight(timestamp - startTime);
    final WeightedSample sample = new WeightedSample(value, itemWeight);
    final double priority = itemWeight / (1.0d - ThreadLocalRandom.current().nextDouble());
    final long newCount = count.incrementAndGet();
    if (newCount <= size) {
      values.put(priority, sample);
    } else {
      Double first = values.firstKey();
      if (first < priority && values.putIfAbsent(priority, sample) == null) {
        // ensure we always remove an item
        while (values.remove(first) == null) {
          first = values.firstKey();
        }
      }
    }
  } finally {
    unlockForRegularUsage();
  }
}

代码示例来源:origin: alibaba/jstorm

/**
 * Adds an old value with a fixed timestamp to the reservoir.
 *
 * @param value     the value to be added
 * @param timestamp the epoch timestamp of {@code value} in seconds
 */
public void update(long value, long timestamp) {
  rescaleIfNeeded();
  lockForRegularUsage();
  try {
    final double itemWeight = weight(timestamp - startTime);
    final WeightedSnapshot.WeightedSample sample = new WeightedSnapshot.WeightedSample(value, itemWeight);
    final double priority = itemWeight / ThreadLocalRandom.current().nextDouble();
    final long newCount = count.incrementAndGet();
    if (newCount <= size) {
      values.put(priority, sample);
    } else {
      Double first = values.firstKey();
      if (first < priority && values.putIfAbsent(priority, sample) == null) {
        // ensure we always remove an item
        while (values.remove(first) == null) {
          first = values.firstKey();
        }
      }
    }
  } finally {
    unlockForRegularUsage();
  }
}

代码示例来源:origin: googleapis/google-cloud-java

.withZone(ZoneOffset.UTC)
    .format(Instant.ofEpochMilli(System.currentTimeMillis())));
if (projects.putIfAbsent(project.getProjectId(), project) != null) {
 return Error.ALREADY_EXISTS.response(
   "A project with the same project ID (" + project.getProjectId() + ") already exists.");

代码示例来源:origin: apache/phoenix

/**
  * Add the passed {@link KeyValue} to the set, only if one is not already set. This is equivalent
  * to
  * <pre>
  * if (!set.containsKey(key))
  *   return set.put(key);
  * else
  *  return map.set(key);
  * </pre>
  * except that the action is performed atomically.
  * @param kv {@link KeyValue} to add
  * @return the previous value associated with the specified key, or <tt>null</tt> if there was no
  *         previously stored key
  * @throws ClassCastException if the specified key cannot be compared with the keys currently in
  *           the map
  * @throws NullPointerException if the specified key is null
  */
 public Cell putIfAbsent(Cell kv) {
  return this.delegate.putIfAbsent(kv, kv);
 }
}

代码示例来源:origin: forcedotcom/phoenix

/**
  * Add the passed {@link KeyValue} to the set, only if one is not already set. This is equivalent
  * to
  * <pre>
  * if (!set.containsKey(key))
  *   return set.put(key);
  * else
  *  return map.set(key);
  * </pre>
  * except that the action is performed atomically.
  * @param kv {@link KeyValue} to add
  * @return the previous value associated with the specified key, or <tt>null</tt> if there was no
  *         previously stored key
  * @throws ClassCastException if the specified key cannot be compared with the keys currently in
  *           the map
  * @throws NullPointerException if the specified key is null
  */
 public KeyValue putIfAbsent(KeyValue kv) {
  return this.delegate.putIfAbsent(kv, kv);
 }
}

代码示例来源:origin: palantir/atlasdb

private byte[] putIfAbsent(Table table, Key key, final byte[] contents) {
  return table.entries.putIfAbsent(key, copyOf(contents));
}

代码示例来源:origin: apache/ignite

IgniteInternalFuture<AffinityInfo> old = affMap.putIfAbsent(key, fut0);
IgniteInternalFuture<AffinityInfo> old = affMap.putIfAbsent(key, fut0);

相关文章

微信公众号

最新文章

更多

ConcurrentSkipListMap类方法