类 IdWorker

java.lang.Object
com.publiccms.common.tools.IdWorker

public class IdWorker extends Object
An object that generates IDs. This is broken into a separate class in case we ever want to support multiple worker threads per process
  • 字段详细资料

    • log

      protected final org.apache.commons.logging.Log log
    • workerId

      private long workerId
    • sequence

      private long sequence
    • workerIdBits

      private long workerIdBits
    • maxWorkerId

      private long maxWorkerId
    • sequenceBits

      private long sequenceBits
    • workerIdShift

      private long workerIdShift
    • timestampLeftShift

      private long timestampLeftShift
    • sequenceMask

      private long sequenceMask
    • lastTimestamp

      private long lastTimestamp
  • 构造器详细资料

    • IdWorker

      public IdWorker(long workerId)
  • 方法详细资料

    • tilNextMillis

      protected long tilNextMillis(long lastTimestamp)
      阻塞到下一个毫秒,直到获得新的时间戳
      参数:
      lastTimestamp - 上次生成ID的时间截
      返回:
      当前时间戳
    • nextId

      public long nextId()
    • timeGen

      protected long timeGen()
      返回以毫秒为单位的当前时间
      返回:
      当前时间(毫秒)