Java Utililty Methods AtomicLong

List of utility methods to do AtomicLong

  1. HOME
  2. Java
  3. A
  4. AtomicLong

Description

The list of methods to do AtomicLong are organized into topic(s).

Method

long add(AtomicLong requested, long n)
Atomically adds the positive value n to the requested value in the AtomicLong and caps the result at Long.MAX_VALUE and returns the previous value.
for (;;) {
 long r = requested.get();
 if (r == Long.MAX_VALUE) {
 return Long.MAX_VALUE;
 long u = addCap(r, n);
 if (requested.compareAndSet(r, u)) {
 return r;
...
long add(AtomicLongFieldUpdater updater, T instance, long n)
Atomically adds the positive value n to the value in the instance through the field updater and caps the result at Long.MAX_VALUE and returns the previous value.
for (;;) {
 long r = updater.get(instance);
 if (r == Long.MAX_VALUE) {
 return Long.MAX_VALUE;
 long u = addCap(r, n);
 if (updater.compareAndSet(instance, r, u)) {
 return r;
...
long addAndGet(AtomicLong current, long toAdd)
Concurrent addition bound to Long.MAX_VALUE.
long u, r;
do {
 r = current.get();
 if (r == Long.MAX_VALUE) {
 return Long.MAX_VALUE;
 u = addCap(r, toAdd);
} while (!current.compareAndSet(r, u));
...
void addstat(Map stat, String key)
addstat
AtomicLong count = stat.get(key);
if (null == count) {
 count = new AtomicLong();
 stat.put(key, count);
count.incrementAndGet();
double average(Stream stream)
Computes the average of Doubles of a stream.
if (stream.isParallel()) {
 throw new UnsupportedOperationException("Parallel stream is not supported");
AtomicLong al = new AtomicLong();
double sum = stream.reduce(0.0, (x, y) -> {
 al.incrementAndGet();
 return x + y;
});
...
boolean compareAndSetIfGreater(final AtomicLong dest, final long tryValue)
If dest only ever monotonically increases, this function is guaranteed to return with dest having a value of at least tryValue and preserves monotonicity.
long destValue;
do {
 destValue = dest.get();
 if (tryValue <= destValue) {
 return false;
} while (!dest.compareAndSet(destValue, tryValue));
return true;
...
AtomicLong createAtomicId()
create Atomic Id
int baseId = new Random(System.currentTimeMillis()).nextInt(1000000) + 20000;
return new AtomicLong((long) baseId);
Long createId(final Long baseId)
create Id
final long delta = ((baseId != null ? baseId.longValue() : 0l) - ID_SEQUENCE.get());
long newId = (delta > 0 ? ID_SEQUENCE.addAndGet(delta) : createId());
return Long.valueOf(newId);
long createObjectID()
create Object ID
return iCounter.addAndGet(1);
String createUniqueFileName(String out)
create Unique File Name
return out + System.currentTimeMillis() + "-" + incrementor.getAndIncrement();


AltStyle によって変換されたページ (->オリジナル) /