The Java Lock interface represents a concurrent lock which can make sure only one thread at a time can lock the lock, perform its critical logic atomically, and unlock the lock again. A Java Lock is similar to a Java Synchronized block, but is more flexible and has more features.
A Java Lock can be reentrant, meaning the same thread can lock the Lock more than one time. The Lock must then be unlocked the same number of times before it is fully unlocked for other threads.
A Java Lock can guarantee fairness among threads waiting to lock the Lock, meaning the threads will be guaranteed to be allowed to lock the Lock in the same sequence the threads called the Lock.lock() method. This prevents the situation of starvation, where a waiting thread is never allowed to lock the Lock because other threads keep "passing" it in the waiting queue.
Chapters:
0:00 Java Lock and ReentrantLock introduction
2:02 Two concurrent Counter class examples
3:38 Lock and unlock the Lock inside a try-finally clause
5:00 Lock reentrance
7:03 Lock reentrance use case
10:24 Lock fairness
14:40 Lock examples
19:25 Lock.lockInterruptibly()
20:42 Lock.tryLock()
24:04 ReentrantLock methods
26:07 Java Lock vs. synchronized blocks - differences and similarities.
Java Lock Tutorial - text:
http://tutorials.jenkov.com/java-util...
Java Synchronized Blocks - text / video:
http://tutorials.jenkov.com/java-conc...
• Java Synchronized - The synchronized ...
Reentrance Lockout - text:
http://tutorials.jenkov.com/java-conc...
Starvation and Fairness - text:
/java-concurrency/starvation-and-fairness.html
Java Concurrency tutorial - text / video playlist:
http://tutorials.jenkov.com/java-conc...
• Java Concurrency and Multithreading
Auf dieser Seite können Sie das Online-Video Java Lock mit der Dauer stunde minuten sekunde in guter Qualität ansehen, das der Benutzer Jakob Jenkov 01 Januar 1970 hochgeladen hat, den Link mit Freunden und Bekannten teilen, dieses Video wurde auf Youtube bereits 46,752 Mal angesehen und es wurde von 1.2 tausend den Zuschauern gefallen. Viel Spaß beim Betrachtenden Zuschauern gefallen!