Skip to content
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

Spring scheduled use wrong thread pool when specific scheduler is used. #7830

Open
jurek7 opened this issue Oct 23, 2024 · 0 comments
Open

Comments

@jurek7
Copy link

jurek7 commented Oct 23, 2024

I observed that wrong thread pool is used when I specify scheduler via scheduler parameter in @scheduled annotation.

package com.grainger.etl.jobs.config;

import java.util.concurrent.TimeUnit;
import lombok.extern.slf4j.Slf4j;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.scheduling.TaskScheduler;
import org.springframework.scheduling.annotation.Scheduled;
import org.springframework.scheduling.concurrent.ThreadPoolTaskScheduler;

@Configuration
@Slf4j
public class POC {

  @Bean
  public TaskScheduler xxxx() {
    ThreadPoolTaskScheduler threadPoolTaskScheduler = new ThreadPoolTaskScheduler();
    threadPoolTaskScheduler.setPoolSize(1);
    threadPoolTaskScheduler.setThreadNamePrefix("xxxx");
    return threadPoolTaskScheduler;
  }

  @Scheduled(fixedRate = 15, timeUnit = TimeUnit.SECONDS, scheduler = "xxxx")
  public void scheduleX() {
    log.info("Scheduled using xxxx thread pool {}", Thread.currentThread().getName());
  }

  @Bean
  public TaskScheduler yyyy() {
    ThreadPoolTaskScheduler threadPoolTaskScheduler = new ThreadPoolTaskScheduler();
    threadPoolTaskScheduler.setPoolSize(1);
    threadPoolTaskScheduler.setThreadNamePrefix("yyyy");
    return threadPoolTaskScheduler;
  }

  @Scheduled(fixedRate = 15, timeUnit = TimeUnit.SECONDS, scheduler = "yyyy")
  public void scheduleY() {
    log.info("Scheduled using yyyy thread pool {}", Thread.currentThread().getName());
  }
}

Output without datadog agent enabled:

2024-10-23T15:19:21.628+02:00  INFO 123249 --- [          xxxx1] com.grainger.etl.jobs.config.POC         : Scheduled using xxxx thread pool xxxx1
2024-10-23T15:19:21.628+02:00  INFO 123249 --- [          yyyy1] com.grainger.etl.jobs.config.POC         : Scheduled using yyyy thread pool yyyy1

Output with datadog enabled(-javaagent:/home/juri/projects/dd-java-agent.jar):

2024-10-23T15:20:55.253+02:00  INFO 125874 --- [pool-3-thread-1] com.grainger.etl.jobs.config.POC         : Scheduled using xxxx thread pool pool-3-thread-1
2024-10-23T15:20:55.254+02:00  INFO 125874 --- [pool-3-thread-1] com.grainger.etl.jobs.config.POC         : Scheduled using yyyy thread pool pool-3-thread-1
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

No branches or pull requests

1 participant