|
@@ -25,6 +25,8 @@ package com.dmdirc.parser.irc.outputqueue;
|
25
|
25
|
import com.dmdirc.parser.common.QueuePriority;
|
26
|
26
|
|
27
|
27
|
import java.io.PrintWriter;
|
|
28
|
+import java.time.LocalDateTime;
|
|
29
|
+import java.time.temporal.ChronoUnit;
|
28
|
30
|
import java.util.Comparator;
|
29
|
31
|
import java.util.concurrent.BlockingQueue;
|
30
|
32
|
|
|
@@ -99,7 +101,8 @@ public abstract class QueueHandler extends Thread implements Comparator<QueueIte
|
99
|
101
|
*/
|
100
|
102
|
@Override
|
101
|
103
|
public int compare(final QueueItem mainObject, final QueueItem otherObject) {
|
102
|
|
- if (mainObject.getTime() < 10 * 1000 && mainObject.getPriority().compareTo(otherObject.getPriority()) != 0) {
|
|
104
|
+ if (!isStarved(mainObject)
|
|
105
|
+ && mainObject.getPriority().compareTo(otherObject.getPriority()) != 0) {
|
103
|
106
|
return mainObject.getPriority().compareTo(otherObject.getPriority());
|
104
|
107
|
}
|
105
|
108
|
|
|
@@ -113,6 +116,17 @@ public abstract class QueueHandler extends Thread implements Comparator<QueueIte
|
113
|
116
|
}
|
114
|
117
|
}
|
115
|
118
|
|
|
119
|
+ /**
|
|
120
|
+ * Determines whether the given item has been starved (i.e., it has sat waiting in the queue
|
|
121
|
+ * for too long due to higher priority items).
|
|
122
|
+ *
|
|
123
|
+ * @param item The item to check
|
|
124
|
+ * @return True if the item has been queued for longer than 10 seconds, false otherwise
|
|
125
|
+ */
|
|
126
|
+ private static boolean isStarved(final QueueItem item) {
|
|
127
|
+ return item.getTime().isBefore(LocalDateTime.now().minus(10, ChronoUnit.SECONDS));
|
|
128
|
+ }
|
|
129
|
+
|
116
|
130
|
/**
|
117
|
131
|
* This is the main even loop of the queue.
|
118
|
132
|
* It needs to handle pulling items out of the queue and calling
|