Using java.util.concurrent.AtomicLong: A numerical id, start at zero and increment by one.
import java.util.concurrent.atomic.AtomicLong; public class Main { public static void main(String[] argv) { AtomicLong nextId = new AtomicLong(); System.out.println(nextId.getAndIncrement()); } }