Class UniqueIdGenerator


  • public class UniqueIdGenerator
    extends Object
    Unique Identifier Generator.

    An id consists of

    1. highest bit is set to 0 to assure positive long.
    2. epoch in ms: 46 bits for 1312 years after the epoch
    3. offset: 10 bits
    4. shard_id: 7 bits

    Idea is borrowed from http://instagram-engineering.tumblr.com/post/10853187575/sharding-ids-at-instagram

    Since:
    2.0.0
    Author:
    Lijun Liao (xipki)
    • Constructor Detail

      • UniqueIdGenerator

        public UniqueIdGenerator​(long epoch,
                                 int shardId)
    • Method Detail

      • nextId

        public long nextId()