A newer version of this documentation is available.

View the latest version

Priority Queue

Priority queue is a regular blocking queue which orders items using a comparator. Items in this queue do not necessarily follow the FIFO or LIFO order; you assign a comparator which defines the order in which items will be stored in the queue. Items with higher priority get polled first, regardless of when they have been added.

Its configuration is same as the regular queue as explained in [configuring-queue] except the additional comparator configuration element. A declarative example is shown below:

  • XML

  • YAML

<queue name="default">
      <item-listener include-value="true">com.hazelcast.examples.ItemListener</item-listener>
        <property name="binary">false</property>
        <property name="memory-limit">10000</property>
        <property name="bulk-load">500</property>
    statistics-enabled: true
    max-size: 10
    backup-count: 1
      - include-value: true
        class-name: com.hazelcast.examples.ItemListener
        class-name: com.hazelcast.QueueStoreImpl
          binary: false
          memory-limit: 1000
          bulk-load: 500
    priority-comparator-class-name: com.hazelcast.collection.impl.queue.model.PriorityElementComparator

The priority-comparator-class-name element is the fully-qualified comparator’s class name to be used for the priority queue. If you do not provide a value, then the queue behaves as a regular FIFO queue.

When you provide a comparator, Hazelcast ignores the queue store memory-limit configuration value.