Starvation and Fairness in Java Threads

Spread the love

Starvation:

Starvation is a situation in which a thread is not granted enough CPU time and it starves to death due to lack of it. This is an un wanted situation for a particular thread and the goal of multi threading is compromised.

Let’s see some of the causes of starvation.

  1. Threads which are having a high priority eat up most of the or all of the CPU time from threads which have a lower priority.
  2. Some Threads are blocked waiting to enter a synchronized block because other threads are continuosly accessing it.
  3. Threads are waiting on an object by calling wait method but are continuosly in wait state and waiting to be notified.

Fairness:

Fairness is a process in which all threads are granted decent amount of time. It is ‘fair’ allocation of CPU time to all threads.

Thanks for reading!!!