Skip to main content

What is Thread starvation? How can a synchronized block cause Thread starvation in Java?


 What is Thread starvation?



In a priority based scheduling, Threads with lower priority get lesser time for execution than higher priority threads.

If a lower priority thread performs a long running computation, it may happen that this thread does not get enough time to finish its computations just in time. 

In such a scenario, the tread with lower priority would starve. It will remain away from the threads with higher priority



How can a synchronized block cause Thread starvation in Java?

It is not defined for synchronization that which thread will enter a synchronized block. 

It may happen that if many threads are waiting for the entry to a synchronized block, some threads may have to wait longer than other threads.

Hence these threads with lower priority will not get enough time to finish their work in time

Comments