Creating a unique timestamp in Java

后端 未结 5 1753
长情又很酷
长情又很酷 2021-02-02 00:20

I need to create a timestamp (in milliseconds) in Java that is guaranteed to be unique in that particular VM-instance. I.e. need some way to throttle the throughput of System.cu

5条回答
  •  情歌与酒
    2021-02-02 00:33

    While searching for a solution I came across ULIB (Universally Unique Lexicographically Sortable Identifier) https://github.com/huxi/sulky/tree/master/sulky-ulid/

    It's not a long, but shorter then UUID.

    A ULID:

    • Is compatible with UUID/GUID's 1.21e+24 unique ULIDs per millisecond (1,208,925,819,614,629,174,706,176 to be exact)
    • Lexicographically sortable
    • Canonically encoded as a 26 character string, as opposed to the 36 character UUID
    • Uses Crockford's base32 for better efficiency and readability (5 bits per character)
    • Case insensitive
    • No special characters (URL safe)

提交回复
热议问题