42 - Resolve False Sharing - SOLUTION - Code Demo 3
@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/backstreetbrogrammer/13_TopCodingInterviewSolutionsInJava
- Top Java Coding Interview Problems Playlist: https://www.youtube.com/playlist?list=PLQDzPczdXrTiEt7nlXb66dgiAjXhhUAUU
- Apache Spark for Java Developers Playlist: https://youtube.com/playlist?list=PLQDzPczdXrTgqEc0uomGYDS0SFu7qY3g3
- Java Serialization Playlist: https://youtube.com/playlist?list=PLQDzPczdXrTjGLkI8kd2d0bfNHx0v7dTy
- Dynamic Programming Playlist: https://youtube.com/playlist?list=PLQDzPczdXrTilRgmNUQ632OrD-wfRLUR_
#java #javadevelopers #javaprogramming #javacodinginterview
Что делает видео по-настоящему запоминающимся? Наверное, та самая атмосфера, которая заставляет забыть о времени. Когда вы заходите на RUVIDEO, чтобы посмотреть онлайн «42 - Resolve False Sharing - SOLUTION - Code Demo 3», вы рассчитываете на нечто большее, чем просто загрузку плеера. И мы это понимаем. Контент такого уровня заслуживает того, чтобы его смотрели в HD 1080, без дрожания картинки и бесконечного буферизации.
Честно говоря, Rutube сегодня — это кладезь уникальных находок, которые часто теряются в общем шуме. Мы же вытаскиваем на поверхность самое интересное. Будь то динамичный экшн, глубокий разбор темы от любимого автора или просто уютное видео для настроения — всё это доступно здесь бесплатно и без лишних формальностей. Никаких «заполните анкету, чтобы продолжить». Только вы, ваш экран и качественный поток.
Если вас зацепило это видео, не забудьте взглянуть на похожие материалы в блоке справа. Мы откалибровали наши алгоритмы так, чтобы они подбирали контент не просто «по тегам», а по настроению и смыслу. Ведь в конечном итоге, онлайн-кинотеатр — это не склад файлов, а место, где каждый вечер можно найти свою историю. Приятного вам отдыха на RUVIDEO!
Видео взято из открытых источников Rutube. Если вы правообладатель, обратитесь к первоисточнику.