Challenge - 5 Problems
Thread Pool Mastery
Get all challenges correct to earn this badge!
Test your skills under time pressure!
❓ component_behavior
intermediate2:00remaining
Thread pool behavior with fixed size
Given a Spring Boot application with a fixed thread pool of size 3, what happens when 5 tasks are submitted simultaneously?
Spring Boot
import org.springframework.context.annotation.Bean; import org.springframework.context.annotation.Configuration; import org.springframework.scheduling.concurrent.ThreadPoolTaskExecutor; @Configuration public class ThreadPoolConfig { @Bean(name = "fixedThreadPool") public ThreadPoolTaskExecutor fixedThreadPool() { ThreadPoolTaskExecutor executor = new ThreadPoolTaskExecutor(); executor.setCorePoolSize(3); executor.setMaxPoolSize(3); executor.setQueueCapacity(10); executor.initialize(); return executor; } }
Attempts:
2 left
💡 Hint
Think about how fixed thread pools handle tasks exceeding the core pool size with a queue.
✗ Incorrect
A fixed thread pool with core and max size 3 can run 3 tasks concurrently. Additional tasks are placed in the queue (capacity 10 here) and wait until a thread is free.
📝 Syntax
intermediate1:30remaining
Correct syntax for custom thread pool bean
Which option correctly defines a Spring Boot ThreadPoolTaskExecutor bean with a core pool size of 5 and max pool size of 10?
Attempts:
2 left
💡 Hint
Look for the correct setter method names and syntax in Java.
✗ Incorrect
The correct methods to set core and max pool sizes are setCorePoolSize(int) and setMaxPoolSize(int). They are called with parentheses and arguments.
🔧 Debug
advanced2:30remaining
Identify the cause of thread pool rejection
A Spring Boot app uses a ThreadPoolTaskExecutor with core size 2, max size 4, and queue capacity 2. When submitting 7 tasks, some are rejected. Why?
Spring Boot
ThreadPoolTaskExecutor executor = new ThreadPoolTaskExecutor(); executor.setCorePoolSize(2); executor.setMaxPoolSize(4); executor.setQueueCapacity(2); executor.initialize(); // 7 tasks submitted simultaneously
Attempts:
2 left
💡 Hint
Consider how tasks are handled when both threads and queue are at capacity.
✗ Incorrect
When the queue is full (2 tasks) and all 4 threads (max pool size) are busy, additional tasks cannot be accepted and are rejected.
❓ state_output
advanced2:00remaining
Thread pool active count after task submission
After submitting 6 tasks to a ThreadPoolTaskExecutor with core size 3, max size 6, and queue capacity 0, what is the active thread count?
Spring Boot
ThreadPoolTaskExecutor executor = new ThreadPoolTaskExecutor(); executor.setCorePoolSize(3); executor.setMaxPoolSize(6); executor.setQueueCapacity(0); executor.initialize(); // Submit 6 tasks simultaneously // Then call executor.getActiveCount()
Attempts:
2 left
💡 Hint
With zero queue capacity, tasks must run immediately or be rejected.
✗ Incorrect
With queue capacity 0, tasks cannot wait in queue. The pool expands up to max size 6 to run all tasks immediately, so active count is 6.
🧠 Conceptual
expert3:00remaining
Effect of allowing core thread timeout
What happens if you configure a ThreadPoolTaskExecutor with allowCoreThreadTimeOut(true) and a keepAliveSeconds of 10?
Spring Boot
ThreadPoolTaskExecutor executor = new ThreadPoolTaskExecutor(); executor.setCorePoolSize(5); executor.setMaxPoolSize(10); executor.setKeepAliveSeconds(10); executor.setAllowCoreThreadTimeOut(true); executor.initialize();
Attempts:
2 left
💡 Hint
Think about what allowing core thread timeout means for thread lifecycle.
✗ Incorrect
Setting allowCoreThreadTimeOut(true) lets core threads terminate if idle longer than keepAliveSeconds, freeing resources when idle.