Note that a BlockingQueue can safely be used with multiple Usage example, based on a typical producer-consumer scenario. Interpreted accordingly when taken by consumers. For example, aĬommon tactic is for producers to insert specialĮnd-of-stream or poison objects, that are Such features tend to be implementation-dependent. Indicate that no more items will be added. So it is possible, for example, forĪddAll(c) to fail (throwing an exception) after addingĪ BlockingQueue does not intrinsically supportĪny kind of "close" or "shutdown" operation to Not necessarily performed atomically unless specified Locks or other forms of concurrency control. Queuing methods achieve their effects atomically using internal Occasional use, such as when a queued message is cancelled.īlockingQueue implementations are thread-safe. Not performed very efficiently, and are intended for only Possible to remove an arbitrary element from a queue using Primarily for producer-consumer queues, but additionally support Reports a remaining capacity of Integer.MAX_VALUE.īlockingQueue implementations are designed to be used Time it may have a remainingCapacity beyond which noĪdditional elements can be put without blocking.Ī BlockingQueue without any intrinsic capacity constraints always Null is used as a sentinel value to indicate failure ofĪ BlockingQueue may be capacity bounded. Implementations throw NullPointerException on attempts These methods are summarized in the following table:Ī BlockingQueue does not accept null elements. Null or false, depending on the operation), the thirdīlocks the current thread indefinitely until the operation can succeed,Īnd the fourth blocks for only a given maximum time limit before giving One throws an exception, the second returns a special value (either Of handling operations that cannot be satisfied immediately, but may be That wait for the queue to become non-empty when retrieving anĮlement, and wait for space to become available in the queue whenīlockingQueue methods come in four forms, with different ways A Queue that additionally supports operations
0 Comments
Leave a Reply. |
AuthorWrite something about yourself. No need to be fancy, just an overview. ArchivesCategories |