The main way to do this is to increase priority when the message is older
thus a low priority message, say an hour ago, has a higher priority than a new high priority message
public class Message implements Comparable<Message>{ private final long time;
as noted in the comments, however, the flow of messages with low priority from a few hours ago will temporarily starve for new messages with high priority, and to ensure their proper use will require a more complex method.
the other method uses several queues, one for each priority, and takes several from a higher priority queue for each of the low priority queued queues
this last method is really effective for a small number of priorities, while the first method I provided can handle an arbitrary number of priorities
source share