BlockingQueue CLASS

A queue with extended capability of blocking on pulling operation until data is available.

With the ordinary queue the dequeue operation returns immediately with the element at the head, or null if the queue is empty. A blocking queue, however, supports dequeuing with extended waiting time, during which it will put the current thread into a waiting thread. When a new element is added, it will notify the waiting threads, so that the dequeue operation can proceed.

Parent Class

All Members


TypeNameSignature
constructorBlockingQueuepublic BlockingQueue()
methoddequeuepublic var dequeue()
methodenqueuepublic void enqueue(var)
methodpullpublic var pull(int, bool)

Constructors


public BlockingQueue()

Create a new blocking queue.


Methods


public var dequeue()

Remove an element from the head of queue.

This method preserves the behavior of the parent class. It won't wait on an empty queue, and it will return null if the queue is empty.

Returns

  • The element to remove; null if the queue is empty. It cannot differentiate between empty queue and null element.

See Also


public void enqueue(var ele)

Add a new element to the tail of queue. This will notify all the threads waiting at the call to pull.

Parameters

  • ele The new eleemnt to add. Can be null.

public var pull(int timeoutInMillisec, bool throwIfTimeout)

Remove an element from the head of queue. If the queue is empty, wait for specified duration. If new data becomes available within the duration this method will return successfully. Otherwise it either returns null, or throws, upon expiration.

This method will send the current thread into waiting state. Use caution to avoid deadlock.

Parameters

  • timeoutInMillisec The time to wait, in milliseconds.
  • throwIfTimeout true if to throw out IllegalStateException upon waiting expiration.

Returns

  • The element to remove; null if the queue is empty. It cannot differentiate between empty queue and null element.

Throws