Java bounded non-blocking buffer for high concurrent situation

前端 未结 5 1800
小蘑菇
小蘑菇 2021-02-06 05:25

Basically I need a data structure to store the temporary chatting messages on the server side. It should be:

  • bounded: because I don\'t need store too many messa

5条回答
  •  死守一世寂寞
    2021-02-06 06:04

    LinkedTransferQueue is a blocking, unbounded queue that doesn't enforce strict FIFO ordering. It will only block when taking from an empty queue, but never on adding to one. You could add a soft cap to evict elements by adding either a size or read & write counters.

    Depending on your requirements, you may be able to write a custom lock-free ring buffer.

提交回复
热议问题