When should I use SynchronousQueue

前端 未结 6 788
無奈伤痛
無奈伤痛 2020-12-22 17:46
new SynchronousQueue()
new LinkedBlockingQueue(1)

What is the difference? When I should use SynchronousQueue against LinkedBlock

6条回答
  •  臣服心动
    2020-12-22 18:15

    SynchronousQueue works in a similar fashion with following major differences: 1) The size of SynchronousQueue is 0 2) put() method will only insert an element if take() method will be able to fetch that element from the queue at the same moment i.e. an element cannot be inserted if the consumer take() call is going to take some time to consume it.

    SynchronousQueue - Insert only when someone will receive it at that moment itself.

提交回复
热议问题