Creating a unique timestamp in Java

后端 未结 5 1756
长情又很酷
长情又很酷 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条回答
  •  旧时难觅i
    2021-02-02 00:22

    Could you perhaps make use of java.util.UUID and it's timestamp() and clockSequence()?

    Method Summary
        int clockSequence() 
            The clock sequence value associated with this UUID.
        long timestamp() 
            The timestamp value associated with this UUID.
    

    More details here: http://docs.oracle.com/javase/1.5.0/docs/api/java/util/UUID.html

提交回复
热议问题