Java tutorial
//package com.java2s; public class Main { static long previousId = System.nanoTime(); public static synchronized String nextUniqueId() { long current = System.nanoTime(); if (current == previousId) { try { Thread.sleep(0, 1); } catch (InterruptedException e) { e.printStackTrace(); } current = System.nanoTime(); } previousId = current; return String.valueOf(current); } }