java.util.concurrent.atomic.AtomicInteger.weakCompareAndSet()方法的使用及代码示例

x33g5p2x  于2022-01-15 转载在 其他  
字(3.8k)|赞(0)|评价(0)|浏览(174)

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

AtomicInteger.weakCompareAndSet介绍

[英]Atomically sets the value to the given updated value if the current value == the expected value.

May fail spuriously and does not provide ordering guarantees, so is only rarely an appropriate alternative to compareAndSet.
[中]如果当前值==预期值,则自动将该值设置为给定的更新值。
May fail spuriously and does not provide ordering guarantees,so很少是compareAndSet的合适替代品。

代码示例

代码示例来源:origin: btraceio/btrace

static boolean weakCompareAndSet(AtomicInteger ai, int i, int j) {
  if (ai instanceof BTraceAtomicInteger) {
    return ai.weakCompareAndSet(i, j);
  } else {
    throw new IllegalArgumentException();
  }
}

代码示例来源:origin: stackoverflow.com

return bits.weakCompareAndSet(floatToIntBits(expect),
               floatToIntBits(update));

代码示例来源:origin: jbachorik/btrace2

/**
 * Atomically sets the value to the given updated value
 * if the current value {@code ==} the expected value.
 *
 * <p>May <a href="package-summary.html#Spurious">fail spuriously</a>
 * and does not provide ordering guarantees, so is only rarely an
 * appropriate alternative to {@code compareAndSet}.
 *
 * @param ai AtomicInteger whose value is weakly compared and set.
 * @param expect the expected value
 * @param update the new value
 * @return true if successful.
 */
public static boolean weakCompareAndSet(AtomicInteger ai, int expect, int update) {
  return ai.weakCompareAndSet(expect, update);
}

代码示例来源:origin: remoting/dubbox

public final boolean weakCompareAndSet(int expect, int update) {
  if (update < 0) {
    throw new IllegalArgumentException("update value " + update + " < 0");
  }
  return i.weakCompareAndSet(expect, update);
}

代码示例来源:origin: remoting/dubbox

public final boolean weakCompareAndSet(int expect, int update) {
  if (update < 0) {
    throw new IllegalArgumentException("update value " + update + " < 0");
  }
  return i.weakCompareAndSet(expect, update);
}

代码示例来源:origin: darren-fu/pampas

public final boolean weakCompareAndSet(int expect, int update) {
  if (update < 0) {
    throw new IllegalArgumentException("update value " + update + " < 0");
  }
  return i.weakCompareAndSet(expect, update);
}

代码示例来源:origin: net.oschina.jmind/jmind-base

public final boolean weakCompareAndSet(int expect, int update) {
  if (update < 0) {
    throw new IllegalArgumentException("update value " + update + " < 0");
  }
  return i.weakCompareAndSet(expect, update);
}

代码示例来源:origin: xuminwlt/j360-datasource

public final boolean weakCompareAndSet(int expect, int update) {
  if (update < 0) {
    throw new IllegalArgumentException("update value " + update + " < 0");
  }
  return i.weakCompareAndSet(expect, update);
}

代码示例来源:origin: com.atlassian.refapp/platform-ctk-plugin

public void reset() {
  if (!calledCount.weakCompareAndSet(1, 0)) {
    throw new IllegalStateException(String.format("Expected <%d> upgrade calls for %s, but was called <%d> times", 1, this.getClass().getName(), calledCount.get()));
  }
}

代码示例来源:origin: yangzhenkun/krpc

public static Address loadbalanceUniformity(String serviceName) {
  ServiceParams serviceParams = ServiceParams.getService(serviceName);
  int total = serviceParams.getAddresses().size();
  count.weakCompareAndSet(Integer.MAX_VALUE,0);
  return serviceParams.getAddresses().get(count.getAndIncrement()%total);
  
}

代码示例来源:origin: dhale/jtk

/**
 * Atomically sets this float to the specified updated value
 * if the current value equals the specified expected value.
 * <p>
 * My fail spuriously, and does not provide ordering guarantees, so
 * is only rarely useful.
 * @param expect the expected value.
 * @param update the updated value.
 * @return true, if successfully set; false, if the current 
 *  value was not equal to the expected value.
 */
public final boolean weakCompareAndSet(float expect, float update) {
 return _ai.weakCompareAndSet(i(expect),i(update));
}

相关文章