java 并发集合

作者: spraysss | 来源:发表于2018-05-27 14:08 被阅读0次

    阻塞集合和非阻塞集合

    • 阻塞集合在增加或删除元素时如果集合已经满了或者集合为空会阻塞。
    • 非阻塞集合不会阻塞而是根据不同的操作会抛异常或返回空。

    阻塞集合有BlockingQueue和BlockingDeque

    • BlockingQueue(阻塞队列)方法总结
    a Throws exception Special value Blocks Times out
    Insert add(e) offer(e) put(e) offer(e, time, unit)
    Remove remove() poll() take() poll(time, unit)
    Examine element() peek() not applicable not applicable
    • BlockingQueue(阻塞双端队列)方法总结

    队头元素 (Head)

    Throws exception Special value Blocks Times out
    Insert addFirst(e) offerFirst(e) putFirst(e) offerFirst(e, time, unit)
    Remove removeFirst() pollFirst() takeFirst() pollFirst(time, unit)
    Examine getFirst() peekFirst() not applicable not applicable

    队尾元素(Tail)

    Throws exception Special value Blocks Times out
    Insert addLast(e) offerLast(e) putLast(e) offerLast(e, time, unit)
    Remove removeLast() pollLast() takeLast() pollLast(time, unit)
    Examine getLast() peekLast() not applicable not applicable

    非阻塞线程安全双端队列

    ConcurrentLinkedDeque

    相关文章

      网友评论

        本文标题:java 并发集合

        本文链接:https://www.haomeiwen.com/subject/azebjftx.html