1 23 24 37 package com.sun.enterprise.instance; 38 39 import java.util.logging.Logger ; 40 import java.util.logging.Level ; 41 import com.sun.logging.LogDomains; 42 43 44 60 public class UniqueIdGenerator { 61 62 63 private long _lastUid = 0; 64 65 66 private static UniqueIdGenerator _instance = null; 67 68 private static Logger _logger = LogDomains.getLogger(LogDomains.CORE_LOGGER); 69 70 static { 71 _instance = new UniqueIdGenerator(); 72 } 73 74 private UniqueIdGenerator() { } 75 76 81 public static UniqueIdGenerator getInstance() { 82 return _instance; 83 } 84 85 91 public long getNextUniqueId() { 92 93 synchronized (this) { 94 while (true) { 95 long uid = System.currentTimeMillis(); 96 97 uid = (uid << 16); 100 101 if (this._lastUid != uid) { 103 this._lastUid = uid; 104 break; 105 } else { 106 try { 107 Thread.currentThread().sleep(1); 108 } catch (InterruptedException ie) { 109 _logger.log(Level.WARNING,"Thread.sleep interrupted ",ie); 111 } 112 } 113 } 114 return this._lastUid; 115 } 116 } 117 } 118 119 | Popular Tags |