java LinkedBlockingQueue和ConcurrentLinkedQueue的区别

实现上看,两者都继承于AbstractQueue,但是ConcurrentLinkedQueue实现了Queue,而LinkedBlockingQueue实现了BlockingQueue,BlockingQueue又继承于Queue,增加了几个额外的阻塞方法,而在ConcurrentLinkedQueue中,并没有阻塞方法。所以从功能上ConcurrentLinkedQueue能做的,LinkedBlockingQueue都能做到,反之不然。

就特性而言,ConcurrentLinkedQueue是线程安全的,也就是遍历的时候不会出现java.util.ConcurrentModificationException(弱一致性),但是性能会有所影响,实际还是看有没有可能有线程会做遍历操作,如果不做遍历的话,LinkedBlockingQueue应该会更加合理。

原文地址:https://www.cnblogs.com/zhjh256/p/6022531.html