DelayQueue trying to use Java DelayQueue , I need to implement the Delayed interface, which requires the compareTo() method , "which provides the ordering that matches its getDelay method." . Of course, the intention is that DelayQueue can easily sort the objects in the queue, so that the next of its delay can be returned to any recipient.
Now I need to also remove objects from the queue ahead of time. I need to call delayQueue.remove(queuedObject) . This, of course, only works if the objects in the queue have the equals() method, which reflects their payload and not the completely unrelated remaining delay time.
As a result, compareTo() based on the remaining delay time, while equals() based on the payload for the objects in the queue, so they are incompatible, as it is "highly recommended" in javadoc Comparable .
Question: am I missing something or is it really a bit of a fad in DelayQueue design?
java equals concurrency compareto
Harald
source share