Skip to content

Use a bounded default executor for the Redis listener container - #4187

Open
vipul080 wants to merge 1 commit into
spring-projects:mainfrom
vipul080:gh-485
Open

vipul080 wants to merge 1 commit into
spring-projects:mainfrom
vipul080:gh-485

Conversation

@vipul080

Copy link
Copy Markdown

Closes gh-485

When no springSessionRedisTaskExecutor bean is defined, the RedisMessageListenerContainer created by RedisIndexedHttpSessionConfiguration falls back to SimpleAsyncTaskExecutor, which starts a new thread for every Redis message.

Changes

  • The container now uses a small subclass that overrides createDefaultTaskExecutor() to return a ThreadPoolTaskExecutor (10 core threads, core thread timeout enabled, thread name prefix spring-session-redis-). Because the container creates this executor itself, it also shuts it down in destroy().
  • When neither springSessionRedisTaskExecutor nor springSessionRedisSubscriptionExecutor is defined, the subscription runs on its own SimpleAsyncTaskExecutor (prefix spring-session-redis-subscription-). Otherwise Spring Data Redis would reuse the dispatch pool for the subscription, and with a blocking connection factory it would hold one of the pool's threads.
  • User-defined executors are used exactly as before. If only springSessionRedisTaskExecutor is defined, it is still used for both dispatch and subscription.
  • Updated the "Redis TaskExecutor" section of the reference docs.

Tests

Added tests to RedisIndexedHttpSessionConfigurationTests for:

  • the default dispatch pool and the separate subscription executor
  • the default pool being shut down when the context closes
  • a user-defined task executor being used for both dispatch and subscription
  • a user-defined task executor not being shut down by the container

./gradlew :spring-session-data-redis:check and :spring-session-data-redis:integrationTest pass locally.

Open questions

  • Is 10 a reasonable default pool size? I took it from the original report and am happy to change it.
  • I targeted main because this changes default behavior. Let me know if it should go to a maintenance branch instead.

Previously, when no springSessionRedisTaskExecutor bean was defined,
RedisMessageListenerContainer fell back to SimpleAsyncTaskExecutor,
which creates a new thread for every Redis message.

Now the container created by RedisIndexedHttpSessionConfiguration
dispatches messages with a ThreadPoolTaskExecutor of 10 threads by
default. The container manages that pool and shuts it down when it is
destroyed. When neither executor bean is defined, the subscription runs
on its own SimpleAsyncTaskExecutor so that it does not hold one of the
dispatch threads. User-defined executors are used as before.

Closes spring-projectsgh-485

Signed-off-by: vipul080 <118840789+vipul080@users.noreply.github.com>
@spring-projects-issues spring-projects-issues added the status: waiting-for-triage An issue we've not yet triaged label Nov 19, 2026
@vipul080
vipul080 marked this pull request as ready for review November 21, 2026 04:01

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

status: waiting-for-triage An issue we've not yet triaged

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Default pool size for the Redis RedisMessageListenerContainer.taskExecutor

2 participants