Thursday, 7 April 2016

What are different concurrent Queues and when they are used ?


BlockingQueue

  • FIFO queue used in designing Producer - Consumer scenarios.
  • provides blocking put and take methods.
    • If the queue is full, put blocks until space becomes available.
    • If queue is empty, take blocks until an element is available.
LinkedBlockingQueue and ArrayBlockingQueue
  • FIFO queues (similar to LinkedList and ArrayList) provides concurrency and better performance than synchronized list.

PriorityBlockingQueue
  • Priority-ordered queue but not FIFO
  • useful when you want to process elements in an order other than FIFO
  • can compare elements according to their natural order using Comparable / Comparartor

SynchronousQueue
  • Not a real queue
  • maintains no space for queued elements; maintains a list of queued threads waiting to queue / dequeue the elements
  • Example
    • In Dish washing producer - consumer scenario, with no dish rack and produce dishes directly to consumer

No comments:

Post a Comment

Note: only a member of this blog may post a comment.