Which Java blocking queue is most efficient for single-producer single-consumer scenarios

后端 未结 7 2191
野的像风
野的像风 2020-12-23 16:32

I\'m working on a standard Java system with critical timing requirements for my producers (1/100s of ms matters).

I have a producer placing stuff in a blocking queu

7条回答
  •  北荒
    北荒 (楼主)
    2020-12-23 17:06

    Well, there really aren't too many options. Let me go through the listed subclasses:

    DelayQueue, LinkedBlockingDeque, PriorityBlockingQueue, and SynchronousQueue are all made for special cases requiring extra functionality; they don't make sense in this scenario.

    That leaves only ArrayBlockingQueue and LinkedBlockingQueue. If you know how to tell whether you need an ArrayList or a LinkedList, you can probably answer this one yourself.

    Note that in LinkedBlockingQueue, "linked nodes are dynamically created upon each insertion"; this might tend to push you toward ArrayBlockingQueue.

提交回复
热议问题