Generating a globally unique identifier in Java

前端 未结 6 1874
广开言路
广开言路 2020-11-29 04:32

Summary: I\'m developing a persistent Java web application, and I need to make sure that all resources I persist have globally unique identifiers to prevent

6条回答
  •  攒了一身酷
    2020-11-29 05:02

    public class UniqueID {
        private static long startTime = System.currentTimeMillis();
        private static long id;
    
        public static synchronized String getUniqueID() {
            return "id." + startTime + "." + id++;
        }
    }
    

提交回复
热议问题