[go: up one dir, main page]

0% found this document useful (0 votes)
6 views1 page

Java Memory Model (JMM)

Uploaded by

gopalv12345678
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
6 views1 page

Java Memory Model (JMM)

Uploaded by

gopalv12345678
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 1

Here’s a short explanation of Java Memory Model (JMM):

• JMM defines how threads interact with memory in Java.

• It controls visibility, ordering, and atomicity of variables between threads.

Key Points:

1. Main Memory vs Thread Local Cache

o Each thread can cache variables.

o Changes in one thread may not be immediately visible to others.

2. Happens-Before Relationship

o A rule to guarantee visibility and ordering.

o Example: Unlocking a lock happens-before another thread acquires that lock.

3. volatile

o Ensures visibility: writes to a volatile variable are visible to all threads


immediately.

o Does not ensure atomicity (except for long/double).

4. synchronized / Locks

o Ensure mutual exclusion + establish happens-before.

5. Atomic Classes (java.util.concurrent.atomic)

o Provide lock-free thread-safe operations.

You might also like