Java AtomicInteger timeToId(long timeInMillis)

Here you can find the source of timeToId(long timeInMillis)

Description

time To Id

License

Apache License

Declaration

public static long timeToId(long timeInMillis) 

Method Source Code

//package com.java2s;
//License from project: Apache License 

import java.util.Random;
import java.util.concurrent.atomic.AtomicInteger;

public class Main {
    private static final int BASE = 100000;
    private static Random RANDOM = new Random(System.currentTimeMillis());
    private static AtomicInteger serial = new AtomicInteger(BASE);

    public static long timeToId(long timeInMillis) {
        if (serial.intValue() > 9900 * BASE) {
            serial.set(BASE);// w w  w .  jav  a 2  s . c  o  m
        }
        return timeInMillis / 1000 * 1000000000 + serial.getAndAdd(BASE) + RANDOM.nextInt(BASE);
    }
}

Related

  1. resetExceptionCount()
  2. setBit(AtomicInteger i, int mask)
  3. setBitByValue(final AtomicInteger ai, final int value)
  4. setBitIfUnsetByIndex(final AtomicInteger ai, final int n)
  5. storeStoreBarrier()
  6. tokenize(String string)
  7. uniqueSequenceId()
  8. waitForAll(List> futures)
  9. waitForEvents(long sleepTime, AtomicBoolean condition, long timeout)