Learn Java Programming - Synchronized Static Method Tutorial

preview_player
Показать описание
The synchronized keyword can be applied to a method or a block of code. The primary purpose of the synchronized keyword is to lock a shared resource to a single thread. The technical term for locking a resource is called an intrinsic lock or monitor lock. In this tutorial I will demonstrate populating an ArrayList from multiple threads using the non-thread-safe add() method. This tutorial will demonstrate applying the synchronized keyword to a static method and a code block to make our method thread safe.
Рекомендации по теме
Комментарии
Автор

sir, thats done quite nicely but i can't understand why you put "synchronized" to displayList method.
because it is not being displayed by all threads but by main thread at the end after filling the ArrrayList.
kindly explain it when you get some time.
thanks

umerwaqas
join shbcf.ru