Java Concurrency Patterns Quiz

Q1. Which method must be called on a Thread object to start a new thread of execution?




Q2. To create a task that can be executed by a thread, a class should implement which interface?




Q3. What is the effect of marking a method or block of code with the synchronized keyword?




Q4. Marking a variable as volatile in Java ensures that:




Q5. Which class provides convenient factory methods to create a thread pool in Java?




Q6. If two threads increment the same counter variable concurrently without any synchronization, what is a likely outcome?




Q7. Which of the following classes is thread-safe for use by multiple threads without additional synchronization?




Q8. What is the term for a situation in which two threads are each waiting for the other to release a lock, so neither can proceed?




Q9. What is a key difference between the Runnable and Callable interfaces in Java?




Q10. If a Java Future’s result is not yet available, what happens when you call Future.get()?




Q11. Which of the following is commonly used to implement the Producer-Consumer pattern safely in Java?




Q12. Which statement correctly describes a difference between Object.wait() and Thread.sleep()?




Q13. Which approach ensures that increments on a shared integer counter are atomic (thread-safe)?




Q14. What must a thread do before calling wait() on an object?




Q15. In a lazy-initialized singleton using the double-checked locking pattern, what is required to make it thread-safe in Java?




Q16. When using Java’s Fork/Join framework, which class should you extend to create a task that returns a result?




Q17. Which feature does ReentrantLock provide that the built-in synchronized mechanism does NOT?




Q18. When a thread catches an InterruptedException, what is the recommended practice?




Q19. Which of the following statements about ConcurrentHashMap is true compared to Hashtable?




Q20. Which concurrency utility is designed to have multiple threads wait for each other at a common barrier point before continuing?




design-patterns