Java AtomicLong createId(final Long baseId)

Here you can find the source of createId(final Long baseId)

Description

create Id

License

Open Source License

Declaration

public static synchronized Long createId(final Long baseId) 

Method Source Code


//package com.java2s;
import java.util.concurrent.atomic.AtomicLong;

public class Main {
    private static final AtomicLong ID_SEQUENCE = new AtomicLong(0l);

    public static synchronized long createId() {
        return ID_SEQUENCE.incrementAndGet();
    }//  w ww  . j ava 2  s .  com

    public static synchronized Long createId(final Long baseId) {
        final long delta = ((baseId != null ? baseId.longValue() : 0l) - ID_SEQUENCE.get());
        long newId = (delta > 0 ? ID_SEQUENCE.addAndGet(delta) : createId());
        return Long.valueOf(newId);
    }
}

Related

  1. addAndGet(AtomicLong current, long toAdd)
  2. addstat(Map stat, String key)
  3. average(Stream stream)
  4. compareAndSetIfGreater(final AtomicLong dest, final long tryValue)
  5. createAtomicId()
  6. createObjectID()
  7. createUniqueFileName(String out)
  8. currentDate()
  9. generateId()