@backstreetbrogrammer
--------------------------------------------------------------------------------
SOLUTION: Resolve False Sharing - Code Demo 3
--------------------------------------------------------------------------------
In computer science, false sharing is a performance-degrading usage pattern that can arise in systems with distributed, coherent caches at the size of the smallest resource block managed by the caching mechanism.
False sharing in Java occurs when two threads running on two different CPUs write to two different variables which happen to be stored within the same CPU cache line. When the first thread modifies one of the variables - the whole CPU cache line is invalidated in the CPU caches of the other CPU where the other thread is running. This means, that the other CPUs need to reload the content of the invalidated cache line - even if they don't really need the variable that was modified within that cache line.
In simpler words, CPU cache is organized in lines of data. Each line can hold 8 longs - 64 bytes. When a visible variable is modified in L1 or L2 cache, all the line is marked "dirty" for the other caches. A read on a dirty line triggers a refresh of this line -: which is to flush the data from main memory.
Write a program to demonstrate false sharing in Java.
Follow up
Modify the program to resolve false sharing and improve performance. (Measure the performance)
Github: https://github.com/backstreetbrogramm...
Top Java Coding Interview Problems Playlist: • Top Java Coding Interview Problems
Apache Spark for Java Developers Playlist: • Apache Spark for Java Developers
Java Serialization Playlist: • Java Serialization
Dynamic Programming Playlist: • Dynamic Programming
#java #javadevelopers #javaprogramming #javacodinginterview