How to block until a BlockingQueue is empty?

前端 未结 6 2157
逝去的感伤
逝去的感伤 2021-02-02 10:30

I\'m looking for a way to block until a BlockingQueue is empty.

I know that, in a multithreaded environment, as long as there are producers putting items in

6条回答
  •  忘掉有多难
    2021-02-02 11:01

    It's not quite what you want to do, but using a SynchronousQueue would have a very similar effect as your Java/Pseudocode, namely the producer blocking until all of the data has been retrieved by some consumer.

    Only difference being the producer blocking on each put until a consumer comes to retrieve the data, instead of only once at the end. Not sure if that would make a difference in your case. I'd expect it to only make a noticeable difference, if the task performed by the producer is somewhat expensive.

提交回复
热议问题