英文:
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
你是否在寻找一个 BlockingDeque? addLast
不会阻塞并且将元素添加到尾部,而 putLast
会阻塞并且将元素添加到尾部。
英文:
Are you looking for a BlockingDeque? addLast
doesn't block and adds to tail and putLast
blocks and adds to tail.
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论