Task Executor


Java Spring Configuration Multithreading Public New

Easy 

5min


Consider the following Spring bean:

@Component
public class TaskExecutor {

    @Value("${thread.count:10}")
    private int threadCount;
    @Value("worker.thread.name")
    private String threadNameTemplate;
    private AtomicInteger counter = new AtomicInteger();
    private ExecutorService executorService;

    @PostConstruct
    public void init() {
        ThreadFactory threadFactory = (runnable) -> new Thread(threadNameTemplate + counter.incrementAndGet());
        executorService = Executors.newFixedThreadPool(threadCount, threadFactory);
    }
}

Select all of the statements that are correct.

Properties injected with @Value may, among other sources, come from system properties and JVM arguments.
As the values of threadCount and threadNameTemplate are private and have no setters, they cannot be set by Spring.
Initialization will fail because the counter and executorService fields are not managed by Spring.
If a property named "thread.count" is not made available to Spring (i.e. through property files), the value of threadCount field will be 10.
The value of the field threadNameTemplate will always be set to the same value regardless of properties provided to Spring.