List of utility methods to do AtomicLong
Date | currentDate() current Date return new Date(currentTimeMillis()); |
Long | generateId() Creates a unique id. return id.incrementAndGet();
|
String | generateId() generate Id return counter.getAndIncrement() + "-" + System.currentTimeMillis(); |
String | generateRandom() Generates a random String. long next = ATOMIC_COUNT.incrementAndGet(); StringBuffer random = new StringBuffer(); random.append(new Date().getTime()).append('-').append(next); return random.toString(); |
int | get(T stat, AtomicIntegerFieldUpdater get if (reset) { return updater.getAndSet(stat, 0); } else { return updater.get(stat); |
long | getAndAddCap(AtomicLongFieldUpdater Atomically adds the value to the atomic variable, capping the sum at Long.MAX_VALUE and returning the original 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 | getAndAddRequest(AtomicLong requested, long n) Adds n (not validated) to requested and returns the value prior to addition once the addition is successful (uses CAS semantics). while (true) { long current = requested.get(); long next = addCap(current, n); if (requested.compareAndSet(current, next)) { return current; |
long | getAndAddRequest(AtomicLongFieldUpdater Adds n to requested field and returns the value prior to addition once the addition is successful (uses CAS semantics). while (true) { long current = requested.get(object); long next = current + n; if (next < 0) { next = Long.MAX_VALUE; if (requested.compareAndSet(object, current, next)) { return current; ... |
AtomicLongArray | getAtomicLongArraySameLengthAsList(List> list) get Atomic Long Array Same Length As List if (list == null) { return null; return new AtomicLongArray(list.size()); |
String | getBench(Map get Bench long fullScanElapsed = times.get("FullScan").get(); StringBuilder result = new StringBuilder("<b>MicroBench</b> FullScan(ms):" + (fullScanElapsed / amount) / 1000 + " <br><b> Breakdown(%):</b><br>"); for (String key : times.keySet()) { long totalNanos = times.get(key).get(); result.append(key).append(":") .append(Math.round((((double) totalNanos / (double) fullScanElapsed) * 100.0))).append("<br>"); return result.toString(); |