Java bounded non-blocking buffer for high concurrent situation

前端 未结 5 1934
小蘑菇
小蘑菇 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:13

    You could utilize the Apache Commons CircularFifoBuffer. It meets your first and last criteria. To support concurrency, you can wrap the base buffer in it's synchronized version like so:

    Buffer fifo = BufferUtils.synchronizedBuffer(new CircularFifoBuffer());
    

    Good luck on the project.

提交回复
热议问题