How to use the ReentrantLock class in Java as an alternative to synchronized code blocks. ReentrantLocks let you do all the stuff that you can do with synchronized, wait and notify, plus some more stuff besides that may come in handy from time to time.
After starting the video, click the maximise button to make it fullscreen so you can see the code!
Code For This Tutorial
The main program just runs the firstThread() and secondThread() methods in different threads. finish() is called after both threads finish.
Press the return key!
Got return key!
Count is: 20000
The main program (just creates and runs two threads):