Java collections framework: Difference between revisions

Content deleted Content added
Add information on CopyOnWriteArraySet. Add in-line citaiton
Queue implementations: Add in-line citation
Line 139:
====BlockingQueue class====
The
'''{{Javadoc|module=java.base|package=java.util.concurrent|class=BlockingQueue|monotype=y}}''' interface extends <code>Queue</code>,{{sfn|Goetz|Peierls|Bloch|Bowbeer|2006|loc=§5.2 Concurrent collections|pp=84-85}} and can be used more flexibly. <code>BlockingQueue</code> works like a regular <code>Queue</code>, but additions to and removals from the <code>BlockingQueue</code> are blocking.{{sfn|Bloch|2018|loc=Chapter §11 Item 78: Synchronize access to shared mutable data|pp=325-329}} If
{{Javadoc|module=java.base|package=java.util|class=Queue|member=remove(java.lang.Object)|text=remove(Object o)|monotype=y}} is called on an empty <code>BlockingQueue</code>, it can be set to wait either a specified time or indefinitely for an item to appear in the <code>BlockingQueue</code>. Similarly, adding an item using the method {{Javadoc|module=java.base|package=java.util|class=Queue|member=add(java.lang.Object)|text=add(Object o)|monotype=y}} is subject to an optional capacity restriction on the <code>BlockingQueue</code>, and the method can wait for space to become available in the <code>BlockingQueue</code> before returning. <code>BlockingQueue</code> interface introduces a method {{Javadoc|module=java.base|package=java.util|class=BlockingQueue|member=take()|text=take()|monotype=y}} which removes and gets the head of the <code>BlockingQueue</code>, and waits until the <code>BlockingQueue</code> is no longer empty if required.<ref>{{cite web|url=http://docs.oracle.com/javase/7/docs/api/java/util/concurrent/BlockingQueue.html |title=BlockingQueue (Java Platform SE 7) |publisher=Docs.oracle.com |date=2013-06-06 |access-date=2013-08-16}}</ref>{{sfn|Bloch|2018|loc=Chapter §11 Item 81: Prefer concurrency utilities to wait and notify|pp=325-329}}