Java UUID Create generateUuidStringStatic()

Here you can find the source of generateUuidStringStatic()

Description

generate Uuid String Static

License

Open Source License

Declaration

public static synchronized String generateUuidStringStatic() 

Method Source Code

//package com.java2s;
/*/*from w ww.j a  v a 2s  . c  om*/
 // This software is subject to the terms of the Eclipse Public License v1.0
 // Agreement, available at the following URL:
 // http://www.eclipse.org/legal/epl-v10.html.
 // You must accept the terms of that agreement to use this software.
 //
 // Copyright (C) 2007-2012 Pentaho
 // All Rights Reserved.
 */

import java.util.*;

public class Main {
    private static String previousUuid = "";
    private static final String UUID_BASE = Long.toHexString(new Random()
            .nextLong());

    public static synchronized String generateUuidStringStatic() {
        while (true) {
            String uuid = UUID_BASE
                    + Long.toHexString(System.currentTimeMillis());
            if (!uuid.equals(previousUuid)) {
                previousUuid = uuid;
                return uuid;
            }
            try {
                Thread.sleep(1);
            } catch (InterruptedException e) {
                throw new RuntimeException(e);
            }
        }
    }
}

Related

  1. generateUUIDFileName(String fileName)
  2. generateUUIDFrom(String uuidString)
  3. generateUUIDFromString(String uuid)
  4. generateUUIDName(String filename)
  5. generateUUIDRandom()
  6. generatorToken()
  7. generatorTransactionPath(String namespace)
  8. genMonUUID(String prefix)
  9. genMsgId()