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

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

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

AtomicInteger.getAndUpdate介绍

[英]Atomically updates the current value with the results of applying the given function, returning the previous value. The function should be side-effect-free, since it may be re-applied when attempted updates fail due to contention among threads.
[中]原子地使用应用给定函数的结果更新当前值,并返回以前的值。该函数应该没有副作用,因为当尝试的更新由于线程之间的争用而失败时,可以重新应用该函数。

代码示例

代码示例来源:origin: jshiell/checkstyle-idea

private String tempFileDirectoryName() {
  return String.format("%s%03d", TEMPFILE_DIR_PREFIX, TEMP_FILE_SOURCE.getAndUpdate(incrementUntil
      (MAX_TEMP_FILE_SUFFIX)));
}

代码示例来源:origin: hypercube1024/firefly

public static int getAndIncrement(AtomicInteger i, int maxValue) {
    return i.getAndUpdate(prev -> {
      if (prev < maxValue) {
        return prev + 1;
      } else {
        return maxValue;
      }
    });
  }
}

代码示例来源:origin: com.fireflysource/firefly-common

public static int getAndIncrement(AtomicInteger i, int maxValue) {
    return i.getAndUpdate(prev -> {
      if (prev < maxValue) {
        return prev + 1;
      } else {
        return maxValue;
      }
    });
  }
}

代码示例来源:origin: hypercube1024/firefly

public static int getAndDecrement(AtomicInteger i, int minValue) {
  return i.getAndUpdate(prev -> {
    if (prev > minValue) {
      return prev - 1;
    } else {
      return minValue;
    }
  });
}

代码示例来源:origin: com.fireflysource/firefly-common

public static int getAndDecrement(AtomicInteger i, int minValue) {
  return i.getAndUpdate(prev -> {
    if (prev > minValue) {
      return prev - 1;
    } else {
      return minValue;
    }
  });
}

代码示例来源:origin: pwm-project/pwm

public int next( )
  {
    return incrementer.getAndUpdate( operand ->
    {
      operand++;
      if ( operand >= ceiling )
      {
        operand = floor;
      }
      return operand;
    } );
  }
}

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

@Override
public int takeBlock(ITreeIndexMetadataFrame metaFrame, int count) throws HyracksDataException {
  return currentPageId.getAndUpdate(operand -> operand + count) + 1;
}

代码示例来源:origin: weld/core

void scalePriority() {
  priority.getAndUpdate((p) -> p * ITEM_PRIORITY_SCALE_POWER);
}

代码示例来源:origin: org.jboss.weld.se/weld-se-shaded

void scalePriority() {
  priority.getAndUpdate((p) -> p * ITEM_PRIORITY_SCALE_POWER);
}

代码示例来源:origin: weld/core

void scalePriority() {
  priority.getAndUpdate((p) -> p * ITEM_PRIORITY_SCALE_POWER);
}

代码示例来源:origin: weld/core

void scalePriority() {
  priority.getAndUpdate((p) -> p * ITEM_PRIORITY_SCALE_POWER);
}

代码示例来源:origin: TheHolyWaffle/TeamSpeak-3-Java-API

int getClientTransferId() {
  return clientTransferId.getAndUpdate(id -> (id + 1) & 0xFFFF);
}

代码示例来源:origin: org.jboss.weld.servlet/weld-servlet-shaded

void scalePriority() {
  priority.getAndUpdate((p) -> p * ITEM_PRIORITY_SCALE_POWER);
}

代码示例来源:origin: salesforce/Argus

@Override
  public String next() {
    return items.get(index.getAndUpdate(updater));
  }
};

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

import akka.routing.Routee;
import akka.routing.RoutingLogic;
import scala.collection.immutable.IndexedSeq;

import java.util.concurrent.atomic.AtomicInteger;

public class CircularRoutingLogic implements RoutingLogic {

 final AtomicInteger cycler = new AtomicInteger();

 @Override
 public Routee select(Object message, IndexedSeq<Routee> routees) {
  final int size = routees.size();
  return size == 0 ? null : routees.apply(cycler.getAndUpdate(index -> ++index < size ? index : 0));
 }
}

代码示例来源:origin: com.salesforce.argus/argus-core

@Override
  public String next() {
    return items.get(index.getAndUpdate(updater));
  }
};

代码示例来源:origin: archerfeel/awacs

private String decompile(String namespace, String classname) {
  int index = counter.intValue() % POOL_SIZE;
  counter.getAndUpdate(operand -> operand >= POOL_SIZE ? 0 : operand + 1);
  Decompiler d = decompilerPool.get(index < 0 ? 0 : index);
  if (d != null) {
    File dir = new File(root, namespace);
    File f = new File(dir, classname + ".class");
    if (f.exists() && !f.canRead() && f.isDirectory()) {
      synchronized (d) {
        return d.decompile(dir, f);
      }
    }
  }
  return null;
}

代码示例来源:origin: Merck/Halyard

@Override
public void meet(Service n) throws RuntimeException {
  final int checkpoint = counter.get();
  n.visitChildren(this);
  int pp = counter.getAndIncrement();
  PRIORITY_MAP_CACHE.put(new IdentityWrapper<>(n), pp);
  if (n == node) ret.set(pp);
  counter.getAndUpdate((int count) -> 2 * count - checkpoint + 1); //at least double the distance to have a space for service optimizations
}

代码示例来源:origin: yandex/graphouse

private void initVisibleCounter() {
    visibleChildren.getAndUpdate(operand -> {
      if (operand >= 0) {
        return operand;
      }
      int count = 0;
      for (MetricDir metricDir : getDirs().values()) {
        if (metricDir.visible()) {
          count++;
        }
      }

      for (MetricName metricName : getMetrics().values()) {
        if (metricName.visible()) {
          count++;
        }
      }
      return count;
    });
  }
}

代码示例来源:origin: triplea-game/triplea

@Test
 public void testSumNumbers() {
  final AtomicInteger counter = new AtomicInteger(1);
  final int result = TechAbilityAttachment.sumNumbers(a -> {
   assertEquals(attachment, a);
   return counter.getAndUpdate(i -> i * -10);
  }, "NamedAttachable{name=test}", mock(PlayerId.class), data);
  assertEquals(101, result);
 }
}

相关文章