Skip to content

Commit

Permalink
Fix apache#16978 AbstractDelayEvent compare method is incorrect
Browse files Browse the repository at this point in the history
  • Loading branch information
lile committed Jan 23, 2025
1 parent 352b47b commit 82279d0
Showing 1 changed file with 4 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,8 @@ public abstract class AbstractDelayEvent implements IEvent, Delayed {
@Builder.Default
protected long createTimeInNano = System.nanoTime();

protected long expiredTimeInNano;

public AbstractDelayEvent() {
this(DEFAULT_DELAY_TIME);
}
Expand All @@ -50,6 +52,7 @@ public AbstractDelayEvent(final long delayTime) {
public AbstractDelayEvent(final long delayTime, final long createTimeInNano) {
this.delayTime = delayTime;
this.createTimeInNano = createTimeInNano;
this.expiredTimeInNano = this.delayTime * 1_000_000 + this.createTimeInNano;
}

@Override
Expand All @@ -60,7 +63,7 @@ public long getDelay(TimeUnit unit) {

@Override
public int compareTo(Delayed other) {
return Long.compare(this.createTimeInNano, ((AbstractDelayEvent) other).createTimeInNano);
return Long.compare(this.expiredTimeInNano, ((AbstractDelayEvent) other).expiredTimeInNano);
}

}

0 comments on commit 82279d0

Please sign in to comment.