Is LinkedList thread-safe when I'm accessing it with offer and poll exclusively?

后端 未结 4 1836
长情又很酷
长情又很酷 2020-12-09 03:07

I have a linked list samples:

protected LinkedList samples = new LinkedList();

I\'m append

4条回答
  •  渐次进展
    2020-12-09 03:32

    That is correct - LinkedList is not synchronized and thus not thread safe. If you do not want to use the newer synchronized analogies of LinkedList, namely, ConcurrentLinkedQueue or LinkedBlockingQueue, you can initialize LinkedList like this:

    LinkedList samples = (LinkedList)Collections.synchronizedList(new LinkedList());
    

提交回复
热议问题