Main.java Source code

Java tutorial

Introduction

Here is the source code for Main.java

Source

//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);
    }
}