A newer version of IMDG is available.

View latest

Want to try Hazelcast Platform?

We’ve combined the in-memory storage of IMDG with the stream processing power of Jet to bring you the all new Hazelcast Platform.

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