Home » Java Basics » 06 - Threads and GUIs
6

Deadlock, Starvation, and Livelock

How to use the deadlock, starvation and livelock

Sometimes, thread 'A''s execution may be suspended until a certain action takes place or some variable is set in thread 'B'. Meanwhile, thread 'B' may be implemented to wait for a positive status flag before execution. This status flag may be handled only in Thread 'A''s suspended section. Thread A and thread B end up waiting for each other indefinitely. This situation is called deadlock. Livelock is conceptually the opposite of deadlock. Instead of waiting on each other, faulty implementation may throw two threads into the loop of continually responding to each other.

Thread Starvation takes place when higher priority threads access synchronized methods so frequently that lower priority threads are constantly blocked and never gets a chance to execute the method. Threaded programs should be designed in a way that deadlock, livelock, and starvation does not occur.