ConcurrentLinkedQueue Code Explanation

后端 未结 2 427
悲哀的现实
悲哀的现实 2020-12-31 21:18

http://www.java2s.com/Open-Source/Java-Open-Source-Library/7-JDK/java/java/util/concurrent/ConcurrentLinkedQueue.java.htm

The above is the source code of ConcurrentL

相关标签:
2条回答
  • 2020-12-31 22:14

    The ConcurrentLinkedQueue allows concurrent modification of the internal list while traversing it. This implies that the node you are looking at could have been removed concurrently. To detect such situations the next pointer of a removed node is changed to point to itself. Look at updateHead (L302) for details.

    0 讨论(0)
  • 2020-12-31 22:22

    The condition asks the question "Is the current node the same as the next node?"

    If so, you've fallen off list ( documentation in line. )

    The basic outline of steps is:

    1. create a new node for the offered data.
    2. walk the list to find the last node
    3. insert new node as new tail.

    The other parts of the if statement are handling concurrent modification issues.

    To better understand what's going on, read Node.casTail() and the casNext()

    0 讨论(0)
提交回复
热议问题