-
Notifications
You must be signed in to change notification settings - Fork 38.3k
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
With virtual threads enabled, long-running fixedDelay
tasks block fixedRate
tasks
#33408
Comments
This behavior is an immediate consequence of the single scheduler thread within the internal Arguably fixed-delay tasks are just not idiomatic on Do you see yourself using |
I guess so, but wouldn't it be possible for the scheduling infrastructure to auto-detect the number of scheduling threads required to run all the registered tasks without blocking each other? scheduleWithFixedDelay(task, delay) {
executor.execute(() -> {
while(!cancelled) {
task.run();
sleep(delay);
}
});
} This should allow an arbitrary number of fixed-delay and fixed-rate tasks to run concurrently without blocking each other. As additional context on why I feel there's definitely room for improvement, here's how I got here (and I imagine I'm not the only one):
Backing up a bit, I can totally accept that |
I ended up separating the trigger executor from the fixed-delay executor, with This hopefully still adheres to the "simple" characteristics of this scheduler variant while addressing the immediate problem at hand. If this is not sufficient in a given scenario and a configurable pool size for concurrent fixed-delay tasks is actually preferable, I would recommend a manually configured |
Framework: 6.1.11
Boot: 3.3.2
Reproducer: demo.zip
As discussed in #31900 and documented in the reference docs, with virtual threads enabled,
fixedDelay
tasks run on a single thread. However, a long-runningfixedDelay
task also blocks concurrentfixedRate
tasks. This behaviour isn't documented and not obvious (to me at least), so I would consider this a bug.Consider the following app:
This prints:
"fixedRate"
every second, as expected.fixedDelay
task kicks in and performs some work for 10 seconds. While that's going on, no furtherfixedRate
tasks are run.fixedDelay
task completes and we get a bunch of"fixedRate"
messages again. Then, we continue with the regular schedule of one message per second.While debugging this, I found that the
SimpleAsyncTaskScheduler
that is used under the covers uses its first thread,scheduling-1
, both to run thefixedDelay
task, and to schedule thefixedRate
tasks. This means ifscheduling-1
is busy running a task, it can't submit newfixedRate
tasks for execution.The text was updated successfully, but these errors were encountered: