JMM (Java Memory Model) Interview Questions
JMM Basics
1. What is the Java Memory Model (JMM)?
2. What’s the difference between JMM and JVM memory structure?
3. What are main memory and working memory?
4. What are the three main characteristics of JMM?
Visibility
5. What is the visibility problem?
6. How to ensure visibility?
7. How does volatile ensure visibility?
8. How does synchronized ensure visibility?
Atomicity
9. What is atomicity?
10. How to ensure atomicity?
11. Is i++ operation atomic? Why?
12. Are long and double assignments atomic?
Ordering
13. What is instruction reordering?
14. Why does instruction reordering happen?
15. How to prevent instruction reordering?
16. What is the happens-before principle?
17. What are the common happens-before rules?
Memory Barriers
18. What are memory barriers?
19. What types of memory barriers exist?
20. How does volatile use memory barriers?
21. How does synchronized use memory barriers?
Singleton Pattern
22. Why does Double-Checked Locking (DCL) need volatile?
23. What’s the problem with DCL without volatile?
24. How to implement thread-safe singleton pattern?
Object Creation
25. What is the object creation process?
26. What is the memory layout of an object?
27. What is the object header? What information does it contain?
28. What is the half-initialized state?
Other Questions
29. What is the role of the final keyword in JMM?
30. How to understand as-if-serial semantics?
Last updated on