多线程阻塞队列 – 添加到头部

huangapple go评论82阅读模式
英文:

multithreaded BlockingQueue - add at the head

问题

我在使用 BlockingQueue 时遇到了问题。

当我将其用作队列时,它对我很有效。然而,有时候我想把几个任务重新添加到队列的头部。

我猜 BlockingQueue 不能执行这种操作。

是否有其他的数据结构可以执行此操作并且是线程安全的?我想避免使用 Collections.synchronizedList(),但我不知道如何利用 java.utils.concurrent 中的功能来实现这样的问题。

请问有哪种数据结构能够在多线程环境中支持这样的问题?

英文:

I have a problem with BlockingQueue.

It is working for me when I use it as the queue. However, sometimes I would like to return several tasks to the queue to the head.

I assume BlockingQueue is not able to do that operation.

Is any other structure is able to do that and is ThreadSafe? I would like to avoid Collections.synchronizedList() but I do not have any idea how to implement such problem with java.utils.concurrent possibilities?

Any hints which structure is able to support such a problem in multi-threaded environment, please?

答案1

得分: 3

你是否在寻找一个 BlockingDequeaddLast 不会阻塞并且将元素添加到尾部,而 putLast 会阻塞并且将元素添加到尾部。

英文:

Are you looking for a BlockingDeque? addLast doesn't block and adds to tail and putLast blocks and adds to tail.

huangapple
  • 本文由 发表于 2020年8月26日 23:19:06
  • 转载请务必保留本文链接:https://go.coder-hub.com/63600699.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定