concurrency - Does java.util.concurrent.Delayed really force me to violate equals/compareTo consistency? -



concurrency - Does java.util.concurrent.Delayed really force me to violate equals/compareTo consistency? -

trying utilize java's delayqueue, have implement delayed interface requires compareto() "method provides ordering consistent getdelay method.". intention of course of study delayqueue can sort queued objects such next 1 running out of delay can returned taker.

now have need remove objects queue ahead of time. need phone call delayqueue.remove(queuedobject). of course of study works if queued objects have equals() method reflects payload , not unrelated remaining delay time.

as result, compareto() based on remaining delay time while equals() based on payload of queued objects, not consistent, "strongly recommended" in javadoc of comparable.

question: missing or indeed bit of quirk in design of delayqueue?

the available wiggle room may in ambiguity of requirement ths ordering consistent getdelay method. consistent mean? can mean using getdelay values primary ordering, , allowing utilize of other attributes secondary ordering, break ties objects have equivalent getdelayvalues? if so, ok if equals method requires equality of getdelay values , attributes compareto method uses tie breaking, not require equality of other attributes. means delayed class must have value semantics.

java concurrency equals compareto

Comments

Popular posts from this blog

php - Android app custom user registration and login with cookie using facebook sdk -

django - Access session in user model .save() -

php - .htaccess Multiple Rewrite Rules / Prioritizing -