Skip to content

Timer: Add callback users can override to cleanup on cancellation#14571

Merged
normanmaurer merged 2 commits into
4.2from
timer_cancelled
Dec 13, 2024
Merged

Timer: Add callback users can override to cleanup on cancellation#14571
normanmaurer merged 2 commits into
4.2from
timer_cancelled

Conversation

@normanmaurer
Copy link
Copy Markdown
Member

Motiviation:

When a TimerTask is cancelled it is useful to sometimes do some cleanup.

Modification:

Add new default method that people can use

Result:

Fixes #14566

Motiviation:

When a TimerTask is cancelled it is useful to sometimes do some cleanup.

Modification:

Add new default method that people can use

Result:

Fixes #14566
@normanmaurer
Copy link
Copy Markdown
Member Author

/cc @He-Pin

@normanmaurer normanmaurer added this to the 4.2.0.Final milestone Dec 13, 2024
@He-Pin
Copy link
Copy Markdown
Contributor

He-Pin commented Dec 13, 2024

I think this should be backported to 4.1.x too.

@normanmaurer
Copy link
Copy Markdown
Member Author

@He-Pin we could only do this in 4.1 by adding some extra interface or abstract base-class tho

@He-Pin
Copy link
Copy Markdown
Contributor

He-Pin commented Dec 13, 2024

That's true, we can live with that, an extra instanceOf seems will not hurt much performance of the Timer.

Comment thread common/src/test/java/io/netty/util/HashedWheelTimerTest.java
@normanmaurer normanmaurer merged commit 4c152ec into 4.2 Dec 13, 2024
@normanmaurer normanmaurer deleted the timer_cancelled branch December 13, 2024 20:54
*
* @param timeout a handle which is associated with this task
*/
default void cancelled(Timeout timeout) {
Copy link
Copy Markdown
Contributor

@He-Pin He-Pin Dec 16, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

should this method be onCancelled or postCancelled?

} else {
timer.pendingTimeouts.decrementAndGet();
}
task.cancelled(this);
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

we should let user know, never do heavy cleanup thing here.

@normanmaurer normanmaurer modified the milestones: 4.2.0.Final, 4.2.0.RC2 Jan 14, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants