Performance: Custom thread pool configuration
MEDIUM IMPACT
This affects how backend tasks are managed and executed, impacting server response time and throughput under load.
import org.springframework.context.annotation.Bean; import org.springframework.scheduling.concurrent.ThreadPoolTaskExecutor; @Bean public ThreadPoolTaskExecutor taskExecutor() { ThreadPoolTaskExecutor executor = new ThreadPoolTaskExecutor(); executor.setCorePoolSize(10); executor.setMaxPoolSize(50); executor.setQueueCapacity(200); executor.setThreadNamePrefix("custom-exec-"); executor.initialize(); return executor; }
import org.springframework.context.annotation.Bean; import org.springframework.scheduling.concurrent.ThreadPoolTaskExecutor; @Bean public ThreadPoolTaskExecutor taskExecutor() { ThreadPoolTaskExecutor executor = new ThreadPoolTaskExecutor(); executor.setCorePoolSize(1); executor.setMaxPoolSize(1); executor.setQueueCapacity(1000); executor.initialize(); return executor; }
| Pattern | Thread Count | Queue Size | Task Wait Time | Verdict |
|---|---|---|---|---|
| Single thread, large queue | 1 | 1000 | High under load | [X] Bad |
| Multiple threads, balanced queue | 10-50 | 200 | Low | [OK] Good |