Duration: 16:00 minutes
Summary: In this video, we continue our discussion of threads. A running thread may enter a blocked/waiting state by calling wait(), sleep(), or join(). The reason it enters that state is that it cannot acquire the lock for a synchronized block of code. The wait method can take the number of milliseconds to wait (for example, 2000 milliseconds, or 2 seconds). The notifyAll() method must be called from a synchronized context. When a thread is waiting as a result of wait(), it releases its lock. In order to ensure the instances of a class can be safely used by multiple threads, we need to synchronize the public methods. If a piece of code does not acquire a lock on t before calling t.wait(), it throws IllegalMonitorStateException.