Concurrent and Blocking Queue in Java

后端 未结 6 2094
一生所求
一生所求 2020-12-12 18:42

I have the classic problem of a thread pushing events to the incoming queue of a second thread. Only this time, I am very interested about performance. What I want to achiev

6条回答
  •  孤街浪徒
    2020-12-12 19:00

    You can try LinkedTransferQueue from jsr166: http://gee.cs.oswego.edu/cgi-bin/viewcvs.cgi/jsr166/src/jsr166y/

    It fulfills your requirements and have less overhead for offer/poll operations. As I can see from the code, when the queue is not empty, it uses atomic operations for polling elements. And when the queue is empty, it spins for some time and park the thread if unsuccessful. I think it can help in your case.

提交回复
热议问题