1
我想知道在這種情況下,ConcurrentLinkedQueue無法從其集合中刪除元素。該項目存在,它在集合內但呼叫ConcurrentLinkedQueue不會刪除
SomeConcurrentLinkedQueue.remove(item)
不會從集合中刪除此項目。收藏是鎖定的還是什麼?
我想知道在這種情況下,ConcurrentLinkedQueue無法從其集合中刪除元素。該項目存在,它在集合內但呼叫ConcurrentLinkedQueue不會刪除
SomeConcurrentLinkedQueue.remove(item)
不會從集合中刪除此項目。收藏是鎖定的還是什麼?
如果ConcurrentLinkedQueue.remove(item)
返回false
,這意味着item
未與任何隊列條目相比較。如果這不是您所期望的,請檢查item
的equals()
方法是否有錯誤。
另一種可能性(通過@Louis沃瑟曼指出)是該隊列包含多個出現item
。 ConcurrentLinkedQueue.remove(item)
只會刪除其中一個。
那麼,這是不是回來'FALSE',因爲我用一個測試,看看如果該項目是在'ConcurrentLinkedQueue': '如果(list.contains(項目)){ \t \t \t Log.d( 「已刪除」, 「刪除」); \t \t \t list.remove(item); \t \t}' 主要問題是該項目仍然存在列表內! – turbodoom 2012-01-30 17:01:04
@turbodoom你的意思是?一個簡單的測試將顯示list.contains(item)在list.remove(item)發生後返回false – 2012-01-30 17:14:46
這可能是因爲您在列表中出現了_multiple_個項目。 'queue.remove(item)'只刪除一個事件。 – 2012-01-30 18:43:51