Can you explain the Java memory model and how it relates to multithreading?
Java memory model defines how threads in a multithreaded environment interact with memory. It ensures visibility of changes made by one thread to other threads. The volatile
keyword ensures that changes to a variable are visible to all threads.