Skip to content

Simplify expired session cleanup jobs #2163

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Sep 23, 2022
Merged

Conversation

vpavic
Copy link
Contributor

@vpavic vpavic commented Sep 20, 2022

At present, RedisIndexedHttpSessionConfiguration and JdbcHttpSessionConfiguration include @EnableScheduling annotated inner configuration classes that configure expired session cleanup jobs. This approach silently opts in users into general purpose task scheduling support provided by Spring Framework, which isn't something a library should do. Ideally, session cleanup jobs should only require a single thread dedicated to their execution and also one that doesn't compete for resources with general purpose task scheduling.

This PR updates RedisIndexedSessionRepository and JdbcIndexedSessionRepository to have them manage their own ThreadPoolTaskScheduler for purposes of running expired session cleanup jobs.

Closes gh-2136

Copy link
Member

@rwinch rwinch left a comment

Choose a reason for hiding this comment

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

I'd prefer that we don't rely on @PostConstruct/@PostDestroy for Beans as this means that the class must be instantiated by a container in order to be used. Instead, I'd consider using InitializingBean and DisposableBean

At present, RedisIndexedHttpSessionConfiguration and JdbcHttpSessionConfiguration include [at]EnableScheduling annotated inner configuration classes that configure expired session cleanup jobs. This approach silently opts in users into general purpose task scheduling support provided by Spring Framework, which isn't something a library should do. Ideally, session cleanup jobs should only require a single thread dedicated to their execution and also one that doesn't compete for resources with general purpose task scheduling.

This commit updates RedisIndexedSessionRepository and JdbcIndexedSessionRepository to have them manage their own ThreadPoolTaskScheduler for purposes of running expired session cleanup jobs.

Closes spring-projectsgh-2136
@rwinch rwinch merged commit 954a40f into spring-projects:main Sep 23, 2022
@rwinch
Copy link
Member

rwinch commented Sep 23, 2022

Thanks for the Pull Request! This is now merged into main 😄

@vpavic vpavic deleted the gh-2136 branch September 23, 2022 20:49
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
in: redis type: enhancement A general enhancement
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Simplify session cleanup related scheduled jobs
2 participants