-
Notifications
You must be signed in to change notification settings - Fork 318
Closed
Milestone
Description
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
Metadata
Metadata
Assignees
Labels
No labels