kafka插入taskEntry节点示意图

112 阅读1分钟

每次添加节点前,移动tail指针

synchronized {
  timerTaskEntry.synchronized {
    if (timerTaskEntry.list == null) {
      // put the timer task entry to the end of the list. (root.prev points to the tail entry)
      val tail = root.prev
      timerTaskEntry.next = root
      timerTaskEntry.prev = tail
      timerTaskEntry.list = this
      tail.next = timerTaskEntry
      root.prev = timerTaskEntry
      taskCounter.incrementAndGet()
      done = true
    }
  }
}

image.png