-2

I have a collection of order objects. The collection gets added to, or updated by a listener that listens to order inserts/updates. Simultaneously, the listener also listens to attribute change (order status) caused by a change in entropy.

eg a change is customer credit rating would update all orders of that customer to a suspended status. On either type of update,the listener updates the orders collection on a single dispatcher thread. A scheduled thread clones and processes the orders collection to update the UI periodically.

The requirement is that:

  1. order updates and inserts should reflect on the UI at the earliest.
  2. bulk status updates should not block/delay order updates and inserts.

What is a recommended data structure and execution strategy for this situation? We are using Java 7.

halfer
  • 19,824
  • 17
  • 99
  • 186
IUnknown
  • 9,301
  • 15
  • 50
  • 76
  • Your title says "priority queue"... – Oliver Charlesworth Aug 29 '16 at 16:50
  • I didn't downvote you, but I have to say that I had a hard time visualizing what your queue actually looks like. Java collections has a number of things which might be useful to you, e.g. `LinkedHashMap`. – Tim Biegeleisen Aug 29 '16 at 16:51
  • 1
    Possible duplicate of [Java: How do I use a PriorityQueue?](http://stackoverflow.com/questions/683041/java-how-do-i-use-a-priorityqueue) – oɔɯǝɹ Aug 29 '16 at 17:08

3 Answers3

0

An easy solution would be to just use two separate queues (a 'live' queue and a 'batch' queue).

The writer can decide to write to the 'live' or the 'batch' queue. The UI can read first from the 'live' queue, and when the 'live' queue is empty, switch to reading from the 'batch' queue (while still checking the 'live' queue in between reads).

You could implement an actual priority queue in this manner as well. Just encapsulate the behavior behind a single queue interface.

oɔɯǝɹ
  • 7,219
  • 7
  • 58
  • 69
0

Sounds to me like a task for queue-structure and separate list-like index to re-order it in non-blocking fashion.

Andrey Lebedenko
  • 1,850
  • 17
  • 24
0

I would probably implement a task queue ,where priority is given to order updates.The UI refresh thread will process the queue ,working on order updates first.

IUnknown
  • 9,301
  • 15
  • 50
  • 76