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

x33g5p2x  于2022-01-17 转载在 其他  
字(13.2k)|赞(0)|评价(0)|浏览(116)

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

ConcurrentHashMap.ensureSegment介绍

[英]Returns the segment for the given index, creating it and recording in segment table (via CAS) if not already present.
[中]

代码示例

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

/**
 * {@inheritDoc}
 *
 * @return the previous value associated with the specified key,
 *         or <tt>null</tt> if there was no mapping for the key
 * @throws NullPointerException if the specified key or value is null
 */
@SuppressWarnings("unchecked")
public V putIfAbsent(K key, V value) {
  Segment<K,V> s;
  if (value == null)
    throw new NullPointerException();
  int hash = hash(key.hashCode());
  int j = (hash >>> segmentShift) & segmentMask;
  if ((s = (Segment<K,V>)UNSAFE.getObject
     (segments, (j << SSHIFT) + SBASE)) == null)
    s = ensureSegment(j);
  return s.put(key, hash, value, true);
}

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

/**
 * Maps the specified key to the specified value in this table.
 * Neither the key nor the value can be null.
 *
 * <p> The value can be retrieved by calling the <tt>get</tt> method
 * with a key that is equal to the original key.
 *
 * @param key key with which the specified value is to be associated
 * @param value value to be associated with the specified key
 * @return the previous value associated with <tt>key</tt>, or
 *         <tt>null</tt> if there was no mapping for <tt>key</tt>
 * @throws NullPointerException if the specified key or value is null
 */
@SuppressWarnings("unchecked")
public V put(K key, V value) {
  Segment<K,V> s;
  if (value == null)
    throw new NullPointerException();
  int hash = hash(key.hashCode());
  int j = (hash >>> segmentShift) & segmentMask;
  if ((s = (Segment<K,V>)UNSAFE.getObject          // nonvolatile; recheck
     (segments, (j << SSHIFT) + SBASE)) == null) //  in ensureSegment
    s = ensureSegment(j);
  return s.put(key, hash, value, false);
}

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

ensureSegment(k);
s.defaultWriteObject();

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

Segment<K,V> segment;
if (retries == RETRIES_BEFORE_LOCK) {
  segment = ensureSegment(j);
  segment.lock();
  lockCount++;

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

Segment<K,V> segment = ensureSegment(i);
segment.lock();
size += segment.count;

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

/**
 * {@inheritDoc}
 *
 * @return the previous value associated with the specified key,
 *         or <tt>null</tt> if there was no mapping for the key
 * @throws NullPointerException if the specified key or value is null
 */
@SuppressWarnings("unchecked")
public V putIfAbsent(K key, V value) {
  Segment<K,V> s;
  if (value == null)
    throw new NullPointerException();
  int hash = hash(key.hashCode());
  int j = (hash >>> segmentShift) & segmentMask;
  if ((s = (Segment<K,V>)UNSAFE.getObject
     (segments, (j << SSHIFT) + SBASE)) == null)
    s = ensureSegment(j);
  return s.put(key, hash, value, true);
}

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

/**
 * {@inheritDoc}
 *
 * @return the previous value associated with the specified key,
 *         or <tt>null</tt> if there was no mapping for the key
 * @throws NullPointerException if the specified key or value is null
 */
@SuppressWarnings("unchecked")
public V putIfAbsent(K key, V value) {
  Segment<K,V> s;
  if (value == null)
    throw new NullPointerException();
  int hash = hash(key.hashCode());
  int j = (hash >>> segmentShift) & segmentMask;
  if ((s = (Segment<K,V>)UNSAFE.getObject
     (segments, (j << SSHIFT) + SBASE)) == null)
    s = ensureSegment(j);
  return s.put(key, hash, value, true);
}

代码示例来源: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 NullPointerException if the specified key or value is null
 */
@SuppressWarnings("unchecked")
public V putIfAbsent(K key, V value) {
  Segment<K,V> s;
  if (value == null)
    throw new NullPointerException();
  int hash = hash(key.hashCode());
  int j = (hash >>> segmentShift) & segmentMask;
  if ((s = (Segment<K,V>)UNSAFE.getObject
     (segments, (j << SSHIFT) + SBASE)) == null)
    s = ensureSegment(j);
  return s.put(key, hash, value, true);
}

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

/**
 * {@inheritDoc}
 *
 * @return the previous value associated with the specified key,
 * or <tt>null</tt> if there was no mapping for the key
 * @throws NullPointerException if the specified key or value is null
 */
@SuppressWarnings("unchecked")
public V putIfAbsent(K key, V value) {
  Segment<K, V> s;
  if (value == null)
    throw new NullPointerException();
  int hash = hash(key.hashCode());
  int j = (hash >>> segmentShift) & segmentMask;
  if ((s = segments[j]) == null)
    s = ensureSegment(j);
  return s.put(key, hash, value, true);
}

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

/**
 * {@inheritDoc}
 *
 * @return the previous value associated with the specified key,
 *         or <tt>null</tt> if there was no mapping for the key
 * @throws NullPointerException if the specified key or value is null
 */
@SuppressWarnings("unchecked")
public V putIfAbsent(K key, V value) {
  Segment<K,V> s;
  if (value == null)
    throw new NullPointerException();
  int hash = hash(key.hashCode());
  int j = (hash >>> segmentShift) & segmentMask;
  if ((s = (Segment<K,V>)UNSAFE.getObject
     (segments, (j << SSHIFT) + SBASE)) == null)
    s = ensureSegment(j);
  return s.put(key, hash, value, true);
}

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

/**
 * {@inheritDoc}
 *
 * @return the previous value associated with the specified key,
 *         or <tt>null</tt> if there was no mapping for the key
 * @throws NullPointerException if the specified key or value is null
 */
@SuppressWarnings("unchecked")
public V putIfAbsent(K key, V value) {
  Segment<K,V> s;
  if (value == null)
    throw new NullPointerException();
  int hash = hash(key.hashCode());
  int j = (hash >>> segmentShift) & segmentMask;
  if ((s = (Segment<K,V>)UNSAFE.getObject
     (segments, (j << SSHIFT) + SBASE)) == null)
    s = ensureSegment(j);
  return s.put(key, hash, value, true);
}

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

/**
 * {@inheritDoc}
 *
 * @return the previous value associated with the specified key,
 *         or <tt>null</tt> if there was no mapping for the key
 * @throws NullPointerException if the specified key or value is null
 */
@SuppressWarnings("unchecked")
public V putIfAbsent(K key, V value) {
  Segment<K,V> s;
  if (value == null)
    throw new NullPointerException();
  int hash = hash(key.hashCode());
  int j = (hash >>> segmentShift) & segmentMask;
  if ((s = (Segment<K,V>)UNSAFE.getObject
     (segments, (j << SSHIFT) + SBASE)) == null)
    s = ensureSegment(j);
  return s.put(key, hash, value, true);
}

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

/**
 * {@inheritDoc}
 *
 * @return the previous value associated with the specified key,
 *         or <tt>null</tt> if there was no mapping for the key
 * @throws NullPointerException if the specified key or value is null
 */
@SuppressWarnings("unchecked")
public V putIfAbsent(K key, V value) {
  Segment<K,V> s;
  if (value == null)
    throw new NullPointerException();
  int hash = hash(key.hashCode());
  int j = (hash >>> segmentShift) & segmentMask;
  if ((s = (Segment<K,V>)UNSAFE.getObject
     (segments, (j << SSHIFT) + SBASE)) == null)
    s = ensureSegment(j);
  return s.put(key, hash, value, true);
}

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

/**
 * Maps the specified key to the specified value in this table.
 * Neither the key nor the value can be null.
 *
 * <p> The value can be retrieved by calling the <tt>get</tt> method
 * with a key that is equal to the original key.
 *
 * @param key key with which the specified value is to be associated
 * @param value value to be associated with the specified key
 * @return the previous value associated with <tt>key</tt>, or
 *         <tt>null</tt> if there was no mapping for <tt>key</tt>
 * @throws NullPointerException if the specified key or value is null
 */
@SuppressWarnings("unchecked")
public V put(K key, V value) {
  Segment<K,V> s;
  if (value == null)
    throw new NullPointerException();
  int hash = hash(key.hashCode());
  int j = (hash >>> segmentShift) & segmentMask;
  if ((s = (Segment<K,V>)UNSAFE.getObject          // nonvolatile; recheck
     (segments, (j << SSHIFT) + SBASE)) == null) //  in ensureSegment
    s = ensureSegment(j);
  return s.put(key, hash, value, false);
}

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

/**
 * Maps the specified key to the specified value in this table.
 * Neither the key nor the value can be null.
 *
 * <p> The value can be retrieved by calling the <tt>get</tt> method
 * with a key that is equal to the original key.
 *
 * @param key key with which the specified value is to be associated
 * @param value value to be associated with the specified key
 * @return the previous value associated with <tt>key</tt>, or
 *         <tt>null</tt> if there was no mapping for <tt>key</tt>
 * @throws NullPointerException if the specified key or value is null
 */
@SuppressWarnings("unchecked")
public V put(K key, V value) {
  Segment<K,V> s;
  if (value == null)
    throw new NullPointerException();
  int hash = hash(key.hashCode());
  int j = (hash >>> segmentShift) & segmentMask;
  if ((s = (Segment<K,V>)UNSAFE.getObject          // nonvolatile; recheck
     (segments, (j << SSHIFT) + SBASE)) == null) //  in ensureSegment
    s = ensureSegment(j);
  return s.put(key, hash, value, false);
}

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

/**
 * Maps the specified key to the specified value in this table.
 * Neither the key nor the value can be null.
 *
 * <p> The value can be retrieved by calling the <tt>get</tt> method
 * with a key that is equal to the original key.
 *
 * @param key key with which the specified value is to be associated
 * @param value value to be associated with the specified key
 * @return the previous value associated with <tt>key</tt>, or
 *         <tt>null</tt> if there was no mapping for <tt>key</tt>
 * @throws NullPointerException if the specified key or value is null
 */
@SuppressWarnings("unchecked")
public V put(K key, V value) {
  Segment<K,V> s;
  if (value == null)
    throw new NullPointerException();
  int hash = hash(key.hashCode());
  int j = (hash >>> segmentShift) & segmentMask;
  if ((s = (Segment<K,V>)UNSAFE.getObject          // nonvolatile; recheck
     (segments, (j << SSHIFT) + SBASE)) == null) //  in ensureSegment
    s = ensureSegment(j);
  return s.put(key, hash, value, false);
}

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

/**
 * Maps the specified key to the specified value in this table.
 * Neither the key nor the value can be null.
 *
 * <p> The value can be retrieved by calling the <tt>get</tt> method
 * with a key that is equal to the original key.
 *
 * @param key key with which the specified value is to be associated
 * @param value value to be associated with the specified key
 * @return the previous value associated with <tt>key</tt>, or
 *         <tt>null</tt> if there was no mapping for <tt>key</tt>
 * @throws NullPointerException if the specified key or value is null
 */
@SuppressWarnings("unchecked")
public V put(K key, V value) {
  Segment<K,V> s;
  if (value == null)
    throw new NullPointerException();
  int hash = hash(key.hashCode());
  int j = (hash >>> segmentShift) & segmentMask;
  if ((s = (Segment<K,V>)UNSAFE.getObject          // nonvolatile; recheck
     (segments, (j << SSHIFT) + SBASE)) == null) //  in ensureSegment
    s = ensureSegment(j);
  return s.put(key, hash, value, false);
}

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

/**
 * Maps the specified key to the specified value in this table.
 * Neither the key nor the value can be null.
 * <p>
 * <p> The value can be retrieved by calling the <tt>get</tt> method
 * with a key that is equal to the original key.
 *
 * @param key   key with which the specified value is to be associated
 * @param value value to be associated with the specified key
 * @return the previous value associated with <tt>key</tt>, or
 * <tt>null</tt> if there was no mapping for <tt>key</tt>
 * @throws NullPointerException if the specified key or value is null
 */
@SuppressWarnings("unchecked")
public V put(K key, V value) {
  Segment<K, V> s;
  if (value == null)
    throw new NullPointerException();
  int hash = hash(key.hashCode());
  int j = (hash >>> segmentShift) & segmentMask;
  if ((s = segments[j]) == null) //  in ensureSegment
    s = ensureSegment(j);
  return s.put(key, hash, value, false);
}

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

/**
 * Maps the specified key to the specified value in this table.
 * Neither the key nor the value can be null.
 *
 * <p> The value can be retrieved by calling the <tt>get</tt> method
 * with a key that is equal to the original key.
 *
 * @param key key with which the specified value is to be associated
 * @param value value to be associated with the specified key
 * @return the previous value associated with <tt>key</tt>, or
 *         <tt>null</tt> if there was no mapping for <tt>key</tt>
 * @throws NullPointerException if the specified key or value is null
 */
@SuppressWarnings("unchecked")
public V put(K key, V value) {
  Segment<K,V> s;
  if (value == null)
    throw new NullPointerException();
  int hash = hash(key.hashCode());
  int j = (hash >>> segmentShift) & segmentMask;
  if ((s = (Segment<K,V>)UNSAFE.getObject          // nonvolatile; recheck
     (segments, (j << SSHIFT) + SBASE)) == null) //  in ensureSegment
    s = ensureSegment(j);
  return s.put(key, hash, value, false);
}

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

/**
 * Maps the specified key to the specified value in this table.
 * Neither the key nor the value can be null.
 *
 * <p> The value can be retrieved by calling the <tt>get</tt> method
 * with a key that is equal to the original key.
 *
 * @param key key with which the specified value is to be associated
 * @param value value to be associated with the specified key
 * @return the previous value associated with <tt>key</tt>, or
 *         <tt>null</tt> if there was no mapping for <tt>key</tt>
 * @throws NullPointerException if the specified key or value is null
 */
@SuppressWarnings("unchecked")
public V put(K key, V value) {
  Segment<K,V> s;
  if (value == null)
    throw new NullPointerException();
  int hash = hash(key.hashCode());
  int j = (hash >>> segmentShift) & segmentMask;
  if ((s = (Segment<K,V>)UNSAFE.getObject          // nonvolatile; recheck
     (segments, (j << SSHIFT) + SBASE)) == null) //  in ensureSegment
    s = ensureSegment(j);
  return s.put(key, hash, value, false);
}

相关文章

微信公众号

最新文章

更多