Reading Java's ConcurrentLinkedQueue Docs, I wonder why it is not possible for the implementation to store the size:
Beware that, unlike in most collections, the size method is NOT a constant-time operation. Because of the asynchronous nature of these queues, determining the current number of elements requires a traversal of the elements.
Where in the source is this "asynchronous nature"?
I only see a while-loop to retry enqueing until the AtomicReferences match the expected values/references. Why is it not possible to increment an size:AtomicInteger
after successfully offering a value to the Queue?
Thanks alot.