Skip to content

An option for SimpleAsyncTaskExecutor to throw an exception when limit is reached #34727

Closed
@dsteb

Description

@dsteb

Hello,

Use-case:

  1. We have an @Async @Retryable task that may fail (e.g. during an incident).
  2. If it fails, we retry N times for M seconds.
  3. Given N, M and RPS, there can be hundred thousands of pending @Async tasks.
  4. We would like to limit concurrency by several thousands, and reject over-limit tasks without affecting a caller of @Async method (without blocking the caller or failing the caller).
  5. We would like to use Virtual Threads.

Using default SimpleAsyncTaskExecutor with concurrencyLimit is not an option as it blocks the caller when limit is reached.

Using ThreadPoolExecutor with Virtual Threads is an option, but it is considered an anti-pattern.

Another option is not to use @Async, but just use virtual threads with a semaphore for example.

Is it possible to implement an option for SimpleAsyncTaskExecutor to throw some TaskRejectedException when limit is reached instead of blocking the caller?

Metadata

Metadata

Assignees

Labels

in: coreIssues in core modules (aop, beans, core, context, expression)type: enhancementA general enhancement

Type

No type

Projects

No projects

Milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions