Java concurrency - improving a copy-on-read collection

后端 未结 5 926
梦毁少年i
梦毁少年i 2021-01-07 06:15

I have a multithreaded application, where a shared list has write-often, read-occasionally behaviour.

Specifically, many threads will dump data into the list, and th

5条回答
  •  忘掉有多难
    2021-01-07 06:47

    You could use a ConcurrentDoublyLinkedList. There is an excellent implementation here ConcurrentDoublyLinkedList.

    So long as you iterate forward through the list when you make your snapshot all should be well. This implementation preserves the forward chain at all times. The backward chain is sometimes inaccurate.

提交回复
热议问题