Happens Before Relationship in Java | Java Multi threading Interview Questions

preview_player
Показать описание
What is happens before relationship in Java, this has been asked multiple times in Java Interviews.

A java candidate must be aware about Visibility, Ordering and Happens Before relationship. This shows candidate has knowledge about basics in Java Multi-threading.

Below are some of the topics that I have already covered. Check my channel for complete list of topics.

* Synchronization in Java

* Race conditions and Data Races in Java

* What is ideal thread pool size

*Thread Priority in Java

Let me know in the comment section if you have any question.

#java #javainterview @multithreading
Рекомендации по теме
Комментарии
Автор

Damn good man. Only nuances will make it to best videos.

rapoliit
Автор

Nice video, good luck in coming videos

meriemasia
Автор

Hi Ajay,
Thanks for the video, but I have one doubt.. after applying synchronization on both methods I tried to test it again and again. But some times I get the following output:
Thread-0 has finished its job.
Thread 2 is printing the value of i: 0 the value should be 20000
I can see my first thread which is incrementing the value of "i" ran first and completed, then T2 ran and printed 0. I don't understand why this is happening, please help.
And can you please tell me the significance of using final Object reference in synchronized block rather than "this".

aakashbadola
Автор

If you swap, t1.start() and t2.start() with each other in the example, it will again break.

darshgupta
Автор

Why to create new Object? Instead just pass this to synchronized block. synchronized (this)

mrunalkubal
visit shbcf.ru