List of utility methods to do AtomicLong
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 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 addstat AtomicLong count = stat.get(key); if (null == count) { count = new AtomicLong(); stat.put(key, count); count.incrementAndGet(); |
double | average(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(); |