Read the summary

Transcript: Java Lock

by Jakob Jenkov

The video's transcript, taken from its captions. Click a timestamp to play the video from that moment.

0:02 the java.log interface represents a lock which can guard a critical section so that only one thread can enter this critical section at a time if you look at the diagram here on the right you can see that i've illustrated that situation thread one here locks the lock enters the critical section and at some point when it's done it will unlock the lock again and then the next thread can lock the lock perform whatever operations it needs inside the critical

0:32 section unlock the lock and let the next thread enter while thread 1 has the lock locked thread 2 and 3 will be blocked trying to lock the lock and then they will not be unblocked until threat 1 unlocks the lock again at the time thread 1 unlocks the lock one of these two threads here will be allowed to lock the lock into the critical section and unlock the lock again afterwards if we look at the code example here on

1:02 the left you can see how to use a lock at first i declare a variable of the type log which is the interface and then i instantiate a new reentrant lock and reentrant lock is a class that implements the lock interface so i can use the reentrant lock instance here as a lock then this example here called lock.lock which locks the lock so that no other threads can lock it then it and here here it's doing nothing but here's

🔒 The rest of the transcript is available with Pro.

🔒 Unlock Premium Features

Access to Transcript is a premium feature. Upgrade now to unlock unlimited studying tools.